Skip to main content
ghost31379
Inspiring
July 1, 2009
Answered

Loaded SWF...dispatchEvent???

  • July 1, 2009
  • 1 reply
  • 1683 views

Here it goes coding world.....can Loaded swfs except customEvents from the parent swf?

What I have Is the Main.swf loading different swfs on screen.

I want to....or I am dispatching a custom event to the screens thats loaded into the Main.swf but they dont receive the call and execute the functions within them.

I have tried just about everything.The Main.swf receives the dispatch call fine but none of the children do. I have the stage listening for the call....like so......

stage.addEventListener(KillEvent.KILLSCREEN, killPage);......

and

stage.dispatchEvent(new KillEvent("killscreens"));

I tried putting

stage.addEventListener(KillEvent.KILLSCREEN, killPage);

in the child.swfs but it keeps saying null object reference error....

and when I take off the "stage" part it compiles but never receives the call

i'm at wits end......and i'm gonna jump....lol

This topic has been closed for replies.
Correct answer kglad

Outstanding ....that works.....never even thought of using a dispatcher like that.....got me scrolling through my notes and books...and websites.....lol

but....the only problem is.....on the project i'm currently doing i cant have the child swf....load and call dispatch because it would kill him when opening

i'm trying to call the kill event from parent with a button click.....when button click......all child swfs thats listening hears it and does the kill function which removes them and garbage collection junk....problem i have is....i push button....nobody listens non-responsive kids....and i'm coding using classes....i'm trying to do my best to stay away from timeline

that stuff you just showed me though...i'm going to play around with that as soon as i'm done with current project.....I got ideas popping all over the place

shucks....

Im gonna turn in my ballot early.... kg for president.....lol soon as im done.....

thx....


each of your swf's that are loaded must have a unique loader.  and i infer that each loaded swf has a main timeline listener and listener function that kills that loaded swf, correct?

if so, use the code i gave whenever you want from any class that has access to the display list (while the loaders are still on the display list) and dispatch your kill event.

because you want to do this when a button is clicked i know you already are in a class that has access to the display list (because the button must be on the display list) so there's nothing extra to do beyond the code i gave (except use it in a button's listener function) and reference the correct loader for the swf you want to kill.

1 reply

kglad
Community Expert
Community Expert
July 1, 2009

the stage is you main swf's stage no matter where you us that reference.  so, you're not going to dispatch anything to a loaded swf using stage as the dispatcher/listener.

if you want code on your loaded swf's main timeline to listener for an event, the main timeline must dispatch it.  you can dispatch that event from the main swf by using:

MovieClip(yourloader.content).dispatchEvent(new Event("killscreens"));

ghost31379
Inspiring
July 1, 2009

hrmmm....sounds like the right thing to do.......but i guess my execution is just sloppy....lol for some odd reason could be due to lack of sleep...but....

back to problem at had ......

this is my load statement from main.swf

public function loadCurrentPage(cpage):void
        {
            var request:URLRequest = new URLRequest(cpage);
            var ldr:Loader = new Loader();
            ldr.load(request);

            addChild(ldr);

        }

so you saying put event listener on ldr...... " ldr.addEventListener(KillEvent.KILLSCREENS, killpage); " and ldr.dispatchEvent...... to dispatch?

if so how will other screens hear that may be on?....i know i'm doing something wrong.....even though i think i followed you correctly even tested it a million more ways and variations of what i think the case may be......but still its not working.....

how do i load yo brains into mine?

and for all the swfs thats listening do i just add....... addEventListener(KillEvent.KILLSCREENS, killpage);......to the main functions of swfs.....

ewww.....i have no code on timelines....may i should try just putting listener on timeline...lol......i'm fishing again lol

thx

kglad
Community Expert
Community Expert
July 1, 2009

on cpage's main timeline use:

this.addEventListener("kill",f);

function f(e:Event){

//do whatever

}


public function loadCurrentPage(cpage):void
        {
            var request:URLRequest = new URLRequest(cpage);
            var ldr:Loader = new Loader();

ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteF);
            ldr.load(request);

            addChild(ldr);

        }

private function onCompleteF(e:Event){

MovieClip(e.target.loader.content).dispatchEvent(new Event("kill"));

}