views:

147

answers:

2

Hi,

I have Flash application (main_container.swf) that loads another swf file (page1.swf).

I want to dispatch an event when page1 has finished, to tell the main_container to close page1.

Is this how you dispatch an event from page1 to the main_container?

parent.dispatchEvent(new Event("pageFinish", true));

Then how do you catch the event from the main_container? I tried this but it didn't work.

loader.addEventListener("pageFinish", OnPage1Finish);

Thank you.

+1  A: 

Simplest way is just

// main, somewhere
loader.content.addEventListener("imDone", imDoneListener);

// page1 timeline/doc class
dispatchEvent(new Event("imDone"));

Of course, you have to wait until the loader has a .content for you to add a listener to, you could either wait for a Event.INIT from loader.contentLoaderInfo before adding your complete listener or dispatching on the loader:

// page1 again, parent.dispatchEvent() would also work
// if you don't reparent the content (which is a bad idea, it confuses Loader)
loaderInfo.loader.dispatchEvent(new Event("imDone"));
Simon Buchan
A: 

Thanks Simon! It works! Perfect!

I'm using the second way because it's simpler (I don't need to add Event.INIT handler)

I'm not sure what you mean by reparent the content though? Thanks a lot!

Doing something like `centralContent.addChild(loader.content)`. This works, but breaks (at least) Loader.unload(). Also, this should probably have been a comment on my answer, if only because I don't get notified :)
Simon Buchan