Tagged with AS3 Bible

Reader Question: Why isn’t event bubbling working

by

A reader sent me this question. Thanks in advance to Michael:

i’m dispatching an event from a sprite after it fades in completely
dispatchEvent(new Event(Main.ENTER_SCREEN_COMPLETE));

i’m trying to listen for to this event but for some reason it doesn’t get picked up when the capturing parameter is set to false.. that is for bubbling and the target phase.

This works
container.addEventListener(Main.ENTER_SCREEN_COMPLETE, screenTweenComplete, true, 0, true);

This does NOT work
container.addEventListener(Main.ENTER_SCREEN_COMPLETE, screenTweenComplete, false, 0, true);

Where container, is an ancestor to everything on the screen. Essentially its the the stage.

Any clues why this is happening?

Answer after the jump.
Continue reading

Tagged

No children on the stage – a confusing Flash CS3 display list issue

by

A reader wrote to me with an interesting Flash CS3 problem that had me stumped at first (mostly because I use FlexBuilder instead of Flash). I thought I’d post the answer here so we can all benefit from it.

The Problem

Ben H. writes…

I’ve been trying to get familiar with a “best practice” on [looping through the display list]. The trouble is, when I enter the following on the first frame of a blank .fla file:

trace("Number of Children in a blank SWF:"+stage.numChildren);
trace("Child 1:" + stage.getChildAt(0));

I get this:

Number of Children in a blank SWF:1
Child 1:[object MainTimeline]

Now that may seem grand, but I’ve drawn several shapes and have a text field and named movieclip instances on stage as well – so why [does it only count one child?]

Solution after the jump.
Continue reading

Tagged