0
votes

My code is simply looping through an xml file and creating 'pages' (which are later animated).

This has all worked fine but now I want to add a sprite over the entire contents of the page if the contents of the xml contain a URL.

At run-time I can see that the checks for the URL are being processed correctly and that the overlay is being generated, but I cannot "see" it on the page.

The following code is located in a for loop for every page in the xml file:

var page:Page = new Page(); //MovieClip in my library
// ... other stuff
var textMC:FadeText = new FadeText(xml); //load the text from the xml fragment for this page
//if the text contains a URL (using RegExp)
if(textMC.hasLink())
{
    var button:Sprite = new Sprite();
    button.graphics.beginFill(0x000000);
    button.graphics.drawRect(0, 0, 1, 1);
    button.name= textMC.getLink();
    button.x = button.y = button.alpha = 0;
    button.width = rectangle.width;
    button.height = rectangle.height;
    button.buttonMode = true;
    button.addEventListener(MouseEvent.CLICK, goToUrl, false, 0, true);
    page.addChildAt(button, page.numChildren);
}
//... more code - such as add page to stage.

From the console (using FireBug and FlashBug) the button is being created, but I cannot see it on screen so I am guessing the addChild bit is at fault.

What is wrong and how do I fix it?

[edit] Having set the alpha to 1 I can see that the overlay IS being added to the page, but it is not changing my cursor or responding to mouse clicks.

I now believe it is something wrong with the XML. It is correctly parsed XML (otherwise FlashPlayer would throw exceptions in my face) and it appears that this code works on every page except the second. Further more, if the second page is set as visible (a flag in the XML determins if the page is created or not) then none of the other pages overlay works.

3
Is your movieclip added to the stage?JNDPNT
I have changed the alpha of the button to 1 - Yes, it is Definitely being added to the page.Richard Parnaby-King
Yeah it is added to page... But is page added to somewhere? That's what I'm wondering :-). You say it's a library movieclip. Is that movieclip also added to your document root/stage?JNDPNT
What is rectangle? Maybe the rectangles width or height is 0.kapex
rectangle is a Rectangle. The Width and Height are set from the width and height of the stage, so that rectangle is now contains the dimensions of stage so that it may be passed to other objects so THEY know the dimensions. Inspecting the object via ExternalInterface and the console shows that button does have the correct height and width. When I set the alpha to 1 I can see that it has been added to the stage but it does not change the cursor or do anything when clicked on, suggesting that there is something else over the top of that...Richard Parnaby-King

3 Answers

1
votes

Sorry to necro this thread but one thing I can think of is that because you specify a z-position to place your page it might be that the z-position generated by (i+1) is not the next one in line. AS3 doesn't allow display-objects to be placed on 'layers' with empty 'layers' between them which was allowed in AS2.

My guess is that during the loop at one point or another the loop doesn't generate a page which leaves an empty layer. The reason why the stage.addChild(page) actually works is because it simply searches for the next empty layer in that stack because you don't specify it.

0
votes
button.x = button.y = button.alpha = 0;

set alpha to 1

button.alpha = 1;

and check for rectangle.width , rectangle.height

last thing, check for textMC.hasLink() if its true or not. If its true, there is another problem with your code that is not related to this sample code.

0
votes

Illogical answer:

Replaced stage.addChildAt(page,i+1); with stage.addChild(page);.

I was clutching at straws. Have spent FAR too long working on this blip, but it works! I don't know WHY it works, and at this point I don't care; IT WORKS!!! (sorry for the unprofessionalism however I have spent two and a half days working on this and have just got it working!)

If someone wants to explain why it works, feel free. I would VERY much prefer to learn why this occurs that struggle to work around it.