views:

3036

answers:

3

I have an Flash AS3 project that loads external SWFs and controls them in different ways. On some of the loaded SWF files, they have a "Next Selection" button that takes you to a new presentation. On my main externally loaded SWF, I have the code:

setTimeout(function() {dispatchEvent(new Event("nextPresentation", false));}, 4000);

Which automatically move to the next selection in the set. This code works exactly the way I want.

In the next loaded SWF, instead of having a timeout, the user goes through the whole thing where at the end of all the timelines there is a button that says next selection. So I added the following code there:

function nextSelectionClick(evt:MouseEvent) {
    trace('here123');
    dispatchEvent(new Event("nextPresentation", false));
}

For some reason, that event never makes it up to the file that loaded the SWF. I'm sure I'm getting to the click event because I get the trace, but the event never makes it up even though it seems like it should be the exact same behavior as the timeout. What am I missing here? Why would that code behave different from a button click than from a timeout?

Thanks

+2  A: 

Hi,

You're right in that they should be functioning the same, which leaves the giant question of what else is going on in the application. It seems as though though problem is not here, but else where.

I hate to ask a question like this, but are you sure the event is being fired from the root display object? If it is not firing from there you will not hear it externally.

Sorry, but I can't give you much more without seeing more actual code, or knowing more about the situation(s).

Tyler.

Tyler Egeto
Thanks, you answered my question. The event wasn't getting fired from the root which was apperently causing the problem.
Ryan Smith
+1  A: 

I think you've set the bubbles attribute to false. This will prevent the event from bubbling up any further than the container it resides in.

Try this instead:

dispatchEvent(new Event("nextPresentation", true));

Also, regarding organization, I'd make a PresentationEvent class and have SKIP_PREVIOUS and SKIP_NEXT event constants on them. This is more consistent with the event model that ActionScript uses and it cuts down on redundancy. This way you can pass the current presentation and other handy presentation-related data as part of the event.

Soviut
He's right on both counts. You need to set bubbles to true to get it to go up the display list. Or, dispatch it from the root of the SWF. Having it bubble is preferable, as is having custom events.
Troy Gilbert
A: 

I have the same problem and don't know how to fix this :?

aa
I created an function on the main (root) timeline that fired the event instead of sending it from an embedded timeline which seemed to solve the problem.
Ryan Smith