0
votes

I 'm trying to build a game in flash cs5, as3. The game will have a mainboard (mainBoard.swf) and from there I can choose what I want to play (loading different swf file each time). The problem I have is that I can't close the child swf from itself. The code I have wrote is :

mainBoard.fla

var gameLoader:Loader = new Loader();
var loadGameRequest:URLRequest; 

function startGame(eventObject:MouseEvent):void{

    loadGameRequest = new URLRequest("puzzle.swf");     
    gameLoader.load(loadGameRequest);
    gameLoader.x = 0;
    gameLoader.y = 0;
    addChild(gameLoader);
    gameLoader.contentLoaderInfo.addEventListener('unloadGame', unloadSWFGame);     

}

function unloadSWFGame(event:Event):void{
    event.target.removeEventListener('unloadGame', unloadSWFGame);
    removeChild(gameLoader);
    gameLoader.unload();
}

In puzzle.fla I have a "Exit" button and the code for this is :

exit_btn.addEventListener(MouseEvent.CLICK, closeSWF);

function closeSWF(event:MouseEvent):void {
    dispatchEvent(new Event('unloadGame', true)); 
}

As far as I have read, this is the way that I have to use, but it doesn't working. *exit_btn* does nothing.. Can someone help? Am I doing something wrong??

1

1 Answers

0
votes

replace the

gameLoader.contentLoaderInfo.addEventListener('unloadGame', unloadSWFGame);     

with

gameLoader.addEventListener('unloadGame', unloadSWFGame);     

contentLoaderInfo is only for loading events. For mouse events always use display list elements.