This tutorial shows how to control the timeline in a Flash movie. You will learn the essential commands: how to play a movie, how to stop it, how to jump to a particular frame on the timeline.
1 Open a new Flash document. Create a simple motion tween animation that consists of, let’s say, 30 frames. If you are a beginner and don’t know how to do this, I suggest you check the tutorial on creating a basic motion tween animation.
Test your movie, to see if your animation is working properly, before proceeding to the next step and ActionScript.
2 Lock the layer with the animation (you can call it animation or whatever you like). Create a new layer and call it actions. Your timeline should look like the image below.

Stopping the animation
3 The first thing we’ll do is stop the movie from playing, right in the middle of it. Right click in frame 15 of layer actions and choose the Insert Keyframe option from the pop-up menu.
In a Flash movie, ActionScript can be placed in keyframes on the timeline, on movie clips, inside movie clips (on movie clip’s own timeline) and on buttons. ActionScript cannot be placed inside a button!
Press F9 (ALT+F9 on a Mac) or choose Window > Actions and the Actions panel will appear. On top of the window, Actions – Frame should be written, indicating that you are entering the code in a keyframe. Click inside the area for code writing (the right side of the Actions panel) and type
stop();
Close the Actions panel. You should see a small letter “a” inside the frame 15 on the actions layer of your timeline. That is Flash’s way of indicating that some ActionScript code is to be found on that frame.
Test your movie (Control > Test Movie) and you should see it stop right in the middle of animation. Close the movie test window. Now, there is no way of making the animation continue, unless we place something in our movie that will make it possible (or delete the ActionScript we just entered, which we don’t want to do). So, let’s place a button in our movie that will enable us to start the animation again.
Basic interactivity with a button
4 To save time, we will put a ready-made button on the scene. Create a new layer and call it button.
Go to Window > Common Libraries > Buttons and you will see the Button Library appear. Choose a playback-type button and drag it onto the scene.
Be sure that the button is selected: lookm in the Properties panel below the scene and see if it says Button on its left side. If you are not sure if the button is selected, click somewhere on the scene, and then click the button (once). This is important, because if you don’t select the button, you may accidentaly place the ActionScript code on the timeline, which will produce an error, because the ActionScript code intended for a button won’t work on a keyframe in the timeline.
5 Press F9 (ALT+F9 on a Mac) or choose Window > Actions and the Actions panel will appear. On top of the window, Actions – Button should be written (be sure to check that), indicating that you are entering the code on a button. Click inside the area for code writing (the right side of the Actions panel) and type
on (release) {
play();
}
Close the Actions panel. Test your movie, you will see the animation, which will stop in the middle, when it reaches the frame where we put the ActionScript stop(); command. Now press the button, and it will continue, reach the end, start from the beginning and stop again.
The code we entered literally tells Flash: “When the mouse is pressed and released over this button, begin playing the movie from the current frame.” Now, why did I say pressed and released? Well, position your mouse over the button, click it, but don’t release it. Nothing will happen until you release it. If you want to know how to make the button work with different mouse clicks (click and drag, release outside, etc) I suggest you check the tutorial on Creating a flash ad banner from start to finish, where the different possibilities of interaction with the mouse are explained along with the notions of events and event handlers.
6 With the button still selected, open the Actions panel again, and replace the line with the stop(); command with the following (the modified code is shown in bold):
on (release) {
gotoAndPlay(20);
}
Test the movie. When the animation stops, click the button and you’ll see the movie jump to the frame specified between the parenthesis (20 in our case) and start playing from that point on (all the frames in between are skipped). If you want the movie to jump to a certain frame and stop there, type the following code:
on (release) {
gotoAndStop(20);
}
If something isn’t functioning properly, check that you typed the code correctly AND that you placed it on the button, NOT on the timeline. Also, you have to pay attention to the way you’ve written the commands: it has to be gotoAndStop(); because Flash is case-sensitive – you cannot write gotoandstop(); or GoToAndStop(); and expect it to work.
OK? Cool
Now you’ve just made your first interactive Flash movie! If you want, put other buttons on the scene (you can put them on the same layer with the already present button, there aren’t going to be any errors because the buttons aren’t animated), and give different functionality to each button: play, stop, etc.
One last thing: if you wanted, say, make the animation loop between the first and the tenth keyframe, insert a keyframe (right-click and choose Insert Keyframe) in frame 10 in the actions layer. Open the Actions panel and write
gotoAndPlay(1);
in it. That’s it. No on(release) command is necessary, because that kind of code is reserved for a button. Test your movie, and you will see it loop between the 1st and the 10th keyframe.
action script 2 only, cant get to work with 3.
thanks
J
Yes, this is for AS 1 and 2
Hi,
Your explaning , I find it much better than other sites for a beginner.
I tried ” Controlling the timeline with ActionScript ” and found i found it half sucess. But when I put Button , it did not play to the end. Pls,help
this to complete.
Thanks & Regards
Nada
Good Evening Nada,
I’ve been using Flash for about a year now and can do the basics. I want to know more about ActionScript. I want to learn how to do smooth animation. Can you help?
Many Thanks
Paul.
Paul: To have smoother animations, you should increase the speed of your movie. Go to Modify > Document properties and increase theFPS (frames per second) value. 30 fps should be fine.
Wow this helps way more than I ever thought someone on the web would provide w/out money!!! (no Im being serious…)
Any ways thank you Luka!
Hello, I tried to apply action script:
on (release) {
gotoAndPlay(20);
}
on a button, but it said “current selection cannot have actions applied to it” I did not why. I applied it to the button not the timeline (I selected the button and make sure it got selected). FYI, I applied a stop action script on the same keyframe but in different layer (this stop action script is not on a button or anything, it’s on the timeline). Does it matter? Thanks!
Hi,
I am working on my new website at present. It opens with some flash amimation obviously running along a timeline, but I want it to get to a point where the timeline stops but there’s a 3D carousel menu on the last frame, I’m coding this using actionscript 2 (learning how to do it from an online tutorial). However because there’s a stop action in the last frame to prevent the movie from looping flash player doesnt read the actionscript code on the lines below that activate and run the 3d carousel menu.
I want people to be able to choose portfolio items from the carousel, each link sends the viewer to respective html & css pages that match the design of the flash movie.
Can you help me please it’s probably a simple suggestion you could make but I can’t seem to find tha answer anywhere online or in either of the two books I have.
Thanks,
Marc
What I mean is that I need the timeline to stop but the 3D carousel to still work on the last frame.
Sorry I wasn’t very clear previously, well it is early o’clock and I’ve been up all night working on this. lol!
Marc
hey man you can’t apply the action on the button because you are using actionscript 3.0 so you have to change the the action from flash settings actionscript 2.0
Thanks it very simple and its working also
nice tutorial, it help me so much.
Thanks
I’m trying to use a simple button (i.e., button, innerButton, overClip, upClip) with a stop(); & I STILL can’t get it to stop looping!!! What am I doing wrong? I have CS3 & CS4, AS3 & I’ve tried everything I can think of…
amazing !nice post can any body tell me how i can do it with Action Script 3 ??
thanks
can somebody help me? I’d like to stop for a while and play again between each frames.
i want to know how to do thi
variable count = 0;
if this layer .frame go to frame 60 then
{
variable = “something”;
count = +1
}
this is a great tutorial i appreciate it alot and it worked magnificently thank you ……………………………..!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hey Luka,
First off, thanks for this nice tutorial, it’s very helpful for a beginner like me
However, Im trying to create the effect until stp 5 but in AS3, could you help on that? I have been reading arround and found very different line scripts…something looking like
home_btn.addEventListener(MouseEvent.CLICK, homebuttonClicked);
function homebuttonClicked(event:MouseEvent):void
{
gotoAndStop(0)
}
My second question : is AS3 more efficient than AS2 ? like if I decide to make something in AS2 does it mean that I can’t export my movie as a flash10 version?
Thanks in advance
I tried this Actionscript 2.0 code and its not working. Could it be because my buttons are in a separate movie and I am trying to control the scene? Is “Scene 1″ an appropraite name?