Sunday, 21 June 2009

Using scenes in Actionscript 3

Moving between two different scenes in Actionscript 3.0 is a little different to the Actionscript 2.0 version. In AS3 you need to use an event listener, but apart from that everything else is the same as the previous AS2 version.

Below is basic code for moving between two scenes using a button:

stop();
button1_mc.addEventListener(MouseEvent.MOUSE_DOWN,goNext);

function goNext (event:MouseEvent):void {
nextScene();
}

The code above assumes you have two scenes, and a button with the instance name ‘button1_mc’. You will also need a ‘stop();’ function in the second scene. If you want to move back to the previous scene you will need to use the ‘prevScene()’ function.


If you want to move to a particular frame within a scene then you can use the following code below:

stop();
button1_mc.addEventListener(MouseEvent.MOUSE_DOWN,goNext);

function goNext (event:MouseEvent):void {
gotoAndStop(10, “Scene 2”);
}

The code above stops at frame 10 within ‘Scene 2’. You could also use the ‘gotoAndPlay’ which would play from the frame instead of stopping.

Feel free to contact me for any questions or comments and remember to subscribe.

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP