Jump to content
Search Community

Share events between two SWFs

vundev test
Moderator Tag

Recommended Posts

Hi Jack, I am loading external.swf and want to catch some events from it by the main.swf which loads it.

The sheme introduced by adobe is:

// ------- Source in the main.swf ---------
// external.swf is loaded by the loader instance of Loader class
loader.contentLoaderInfo.sharedEvents.addEventListener('MyEvent', onCustomEvent);
loader.load()
function onCustomEvent(event:Event):void
{
	  //events from external.swf are handled here
}

// ------- Source in the external.swf ---------
// the external swf dispatches events like this
this.loadirInfo.sharedEvent.dispatchEvent(new CustomeEvent('MyEvent'))

 

I cant figure out how to do that with SWFLoader?

I can of course, use loader.rawContent.loaderInfo.sharedEvents, but it limitates the things so that the listeners must be put after loading completes

Link to comment
Share on other sites

It is a tricky scenario because in order to work around various gc bugs in Adobe's stuff, SWFLoader must recreate/reinstantiate the Loader instance that it uses internally in certain situations (like when loading is cancelled). So it isn't as simple as just exposing the Loader instance so that you can attach listeners because if for some reason things get cancelled, the Loader would get recreated internally and you'd need to re-add your listeners, etc. You're actually the first person who has ever requested the sharedEvents functionality. The only way I can think of to support that would be to extend and intercept addEventListener() and removeEventListener() calls to the sharedEvents object and keep an internal record of any/all methods and then every time the Loader gets recreated, manually add those listeners each time. That'd add a fair amount of kb and I'd have to add special hooks into the API to grant access. I'm having a very hard time justifying the costs to add that feature that only one person has ever requested, you know?

 

You're welcome to add your own hooks into SWFLoader to give yourself access to the Loader instance if you want (it's just called _loader internally). I realize that's not an ideal solution, but I can't think of a much better one right now that doesn't force everyone to pay a relatively high price for a feature that almost no one uses. See what I mean?

  • Like 1
Link to comment
Share on other sites

I perfectly agree with you and wan't intterupt you again with sharedEvents ... For my project it is not important to add listeners to sharedEvents before loading completes. When loading completes I access the reference to the document class of the loaded swf with rawContent property and put my listeners like this:

loader.rawContent.loaderInfo.sharedEvents.addEventListeners(...)

I was thinking that I'm missing sth into the docs, but ok ...

The reason for using sharedEvents is because I want to skip bubbling events from th eexternal swf. Firstly I was adding my listeners directly to the document class and bubbling them into the external.swf -> overheat. With SharedEvents sends everything in target phase ....

Thanks for the reply

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...