Skip to main content
Inspiring
July 6, 2008
Answered

Listener for dispatched event

  • July 6, 2008
  • 4 replies
  • 301 views
Hi,

I had a problem which the majority of got sorted out with help from other people but it's left me with one last part i dont get...

I have a main.swf which loads into a loader an external swf called menu1.swf. I'm trying to get a function triggered in the main.swf when it recieves an event dispatched from the menu1.swf. The main problem i had was getting the event to dispatch from the loaded swf but that's now sorted. My main problem now is where to add the listener in the main.swf to listen out for this event.

I've been informed it's not the loader i should be attaching the listener to, but rather it's contents ( the function i want to call is to unload the loader once the event from the contents of that loader has been dispatched). Now the contents is menu1.swf, but i didnt think you could attach a listener to a swf? I was also told that once the loader has completed loading, the swf is no longer a swf, but instead becomes content.data...

So what am i attaching a listener to? should it be loader.content.data.addEventlistener(... );

it's got me stumped?
This topic has been closed for replies.
Correct answer kglad
loader.content.addEventListener(...);

(add that loader after loading is complete.)

4 replies

kglad
Community Expert
Community Expert
July 6, 2008
you're welcome.
inquizardAuthor
Inspiring
July 6, 2008
sorted the problem - the function still had (event:MouseEvent) in it instead of (event:Event) in it... oops
inquizardAuthor
Inspiring
July 6, 2008
Hi kglad - thanks for the reply.

Just want to point out im using the TweenMax engine to call the function which will dispatch the event in the loaded.swf.

I've added the code you suggested to the loaderComplete function in my main.swf script like you suggested ( to guarantee their be some content in the loader) and got this:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@4097da9 to flash.events.MouseEvent.
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at menu_1/menu_1::callUnload()[C:\Users\andrew\Desktop\New Folder (2)\work\menu_1.as:164]
at Function/ http://adobe.com/AS3/2006/builtin::apply()
at gs::TweenLite/complete()
at gs::TweenFilterLite/render()
at gs::TweenLite$/executeAll()

dont suppose you know what all that means do you? I've read that theirs a bug in the onComplete tween of the TweenMax engine - any chance that's what this is at all?...
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 6, 2008
loader.content.addEventListener(...);

(add that loader after loading is complete.)