gavin sim logo
 

Week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Week 8

Week 9

Teaching > ActionScript

Understanding the timeline and Scenes


Quick

Create a rectangle on the stage any size and extend it over 50 frames. Create a new layer and then on frame 50 insert a blank keyframe and open the actions panel and type:

Stop();     

Then on frame 1 type the following:

trace(scenes.length);
trace(currentScene.name);
trace(currentScene.numFrames);


Test your movie and in the output window 1 will be displayed as there is 1 scene, followed by Scene 1 which is the name of the scene and 50 which is how many frames are in the scene.


Part 1 - Navigations

Download labels.fla


You will see five layers and the ones we are interested in are the actions and the frame labels. The frame labels enable you to tell the play head when used with the gotoAndPlay or Stop method to go to that particular frame.
On the actions layer, frames 1, 5, 10 & 15 add the following:

Stop();


On the stage is two buttons with instance names of page1 and page2 these match the label names on frame 5 and 10.
On frame 1 of the actions layer add the following code:

page1.addEventListener(MouseEvent.CLICK, newPage);
page2.addEventListener(MouseEvent.CLICK, newPage);

function newPage(evt:MouseEvent):void{
   gotoAndPlay(evt.target.name);
}

Here you are creating the eventListeners for the buttons but unlike previous tutorials you are using just one function (new Page). The evt.target property is sought from the function argument and is used to identify which element received the mouse event. If you pressed page 1 it would be this element and the .name enable you to get the instance name of the element.


Control / Test Movie.


Excercise

Add a page 3 button and then modify the code so that it will go to page 3, you will have to create a frame label for this.