Aximili
Aximili

Reputation: 29484

Flash: Dispatching/handling events

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.

Upvotes: 0

Views: 270

Answers (1)

Simon Buchan
Simon Buchan

Reputation: 13255

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"));

Upvotes: 1

Related Questions