Thursday, 19 April 2012

Creating the exit game button

I found a way of exiting the games so the user returned to the site. I made a Exit Games button and added a instance name of btnUnload. Then I created a function, called unload SWF, whenever the button is Clicked. I then copied the loader variables from each game button so for instance the bolt jigsaw button as a loader of 5 as per code below:

boltjigsaw_button.addEventListener(
MouseEvent.CLICK, boltjigsawGame);



function boltjigsawGame(e:MouseEvent):void
{
var request5:URLRequest = new URLRequest("usainboltjigsaw.swf");
Jigsaw2Sound1.play();
loader5.load(request5);
loader5.x = 70;
loader5.y = 150;
loader5.scaleX = .7; // 1 is 100%; .5 is 50%, 2 is 200% and so on
loader5.scaleY = .7;
addChild(loader5);
}

and the other games are 4, 6 and 7 I added the loader variables so that the unloadSWF function can access them. Then for every loader there is a swf file that loads the games so for instance in the code above the swf is
("usainboltjigsaw.swf");. Then I added the function .load() and addChild() as you can see in the action script above which loads that particular game. Then finally to exit the games on the Exit Games button I added the following code so the user can exit the games when the button is pressed.

btnUnload.addEventListener(MouseEvent.CLICK,unloadSwf);

function unloadSwf(e:MouseEvent):void {
loader4.unload();
loader5.unload();
loader6.unload();
loader7.unload();
//loader.unloadAndStop();
}

So to exit the usain bolt jigsaw game I added loader5.unload(); to the function above and did the same for the other games but just changed the number to 4, 6 and 7.

Below is how it looks on screen so the game is open then when the user wants to exit the game they just click on the Exit Games button.

No comments:

Post a Comment