Using scenes in Actionscript 3

Posted on October 3, 2009. Filed under: Articles |

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.

Advertisement

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.