• Home
tudwaythecore.com
blog
  • Recent Posts

    • Detecting focus in flash player
    • BitmapData PerlinNoise
    • Creating bridges in APE part 2
    • Creating bridges in APE
    • SteerWheels 2
    • Creating a simple APE example
    • Design me some levels!
    • Finished Migrating
  • Recent Comments

    • random on Making a Shooting Game Part 2
    • SammyG on Making a Shooting Game Part 2
    • Jim on Making a Shooting Game Part 2
    • rraven on Making a Shooting Game Part 2
    • Adrian on Making a Shooting Game Part 2
  • Categories

    • APE
    • flash
    • game
    • platform
    • sound
    • tutorial
    • Uncategorized
  • Archives

    • May 2009
    • October 2008
    • September 2008
    • August 2008
    • May 2008
    • April 2008
    • March 2008
  •  

    March 2008
    M T W T F S S
        Apr »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
  • games

    • Game Showcase
Mar 25

Controlling timeline events

flash, tutorial Add comments

In Flash, if you want to stop, play or move to a certain frame in the movie you have to use actionscript.

First – stop. To stop a flash movie you simply have to write stop() in the actions panel of the frame you want the movie to stop at.

Play. This is just as easy as the stop function, just write play(). flash plays movies automatically so you won’t need to use this command as much as stop.
To move forward and backward one frame use nextFrame(), to go forward, and prevFrame(), to go backwards.
The most useful of the timeline controls are the gotoAndStop(num) and the gotoAndPlay(num) functions. To use them just replace “num” with the frame number that you want to play or stop, or even you can replace it with a frame label in “”.
Lets put this in to action with a demo.
Click on the buttons to effect the movie.
The code is as follows : -
import flash.events.MouseEvent;
playbut.addEventListener(MouseEvent.MOUSE_DOWN, playFunction);
stopbut.addEventListener(MouseEvent.MOUSE_DOWN, stopFunction);
nextframebut.addEventListener(MouseEvent.MOUSE_DOWN, nextframeFunction);
prevframebut.addEventListener(MouseEvent.MOUSE_DOWN, prevframeFunction);
function playFunction(Event:MouseEvent):void {
play()
}
function stopFunction(Event:MouseEvent):void {
stop()
}
function nextframeFunction(Event:MouseEvent):void {
nextFrame()
}
function prevframeFunction(Event:MouseEvent):void {
prevFrame()
}
I’m using the same button code from my last tutorial, but replacing the trace(“”) function with the functions i have talked about in this tutorial.
explaining the code:-
line 1 – importing the Mouse Events
line 2 I’m adding event listeners to the buttons instance names that i have. When the mouse is touching playbut and it is pressed, do the playFunction.
line 3-5 same as line 2 but for different functions.
line 6-8 This is the playfunction, which is called every time the playbut is pressed. it makes the flash movie play, as i have explained earlier in the post.
9-17 These are the other functions, called by the event listeners. 
Well, that’s it for timeline events.
If your unsure about buttons, check out my earlier tutorial here 

One Response to “Controlling timeline events”

  1. yelenef Says:
    March 26th, 2008 at 8:29 pm

    Very helpful, thanks :)

Leave a Reply

Powered by WordPress .::. Designed by SiteGround Web Hosting

cssandhtml