PDA

View Full Version : Dispatch Event


nevrothwen
12-29-2010, 11:46 AM
I'm a total noob and don't understand what I'm doing wrong.
I have a main .swf where I load a child .swf. When I click a close button in the child .swf I want that child to be removed. After doing a lot of googling I found the best way to do it is to dispatch an event from my child .swf when the close button is clicked. The problem I think is that this event doesn't get seen by my parent .swf.

Here's the code in the child:
_root.close_btn.onRelease = function() {
var evt = document.createEvent("killMe");
dispatchEvent(evt);
trace("test");
}

and the code in the parent:
private function startSpel(event:Event):void{
game = new Spel();
game.x = stage.stageWidth/2 - game.width/2;
game.y = menu.height+50;
addChild(game);
I = new Loader();
game.addChild(I);
I.load(new URLRequest("Quiz.swf"));
I.addEventListener("killMe", killLoadedClip);
}
private function killLoadedClip(event:Event):void{
trace("killMe");
I.unload();

}

I'm not picking up the trace in my killLoadedClip function.