Wednesday, March 4, 2009

Flash Tip: Easy Timeline Controls

Gotta quick tip for you guys which I also used on the NFL schedule lab also (does it count as cheating?)

Easy way to create timeline controls
now, this trick doesnt work in every situation, especially when you have movies inside movies to make your timeline smaller, but if you have everything on the main timeline (all motions, tweens, etc), here is an easy way to add control to it.

1. Create a layer named TimelineControl.
2. On the first frame in that layer, add buttons that you want to have (stop, play, next, back, rewind, etc)
3. Insert a frame at the very end of your movie (this will make all the buttons span along the whole movie, but only uses 1 'big frame'
4. Now, back to your first frame, and say for example, we want a next button:
-select your next button
-Open the actions window (The diagonal arrow, F9, or Window > Actions)
-Type in this code:

on (release) {
gotoAndStop (_currentframe+5);
}

Thats it. You now have a next button.

This is most helpful if you want your button to move ahead or back a certain amount of frames. If you want just to move a frame forward or a frame back, on click, nextFrame(); would do the job. (and previousFrame(); )

How it works?
Actionscript is a pretty powerful yet simple programming language that follows the idea of most other object oriented programming languages (Java, C++ etc).

"_currentframe" is a flash variable that is updated by flash as the movie plays along, updating the variable to be the current frame that the movie is in. When we do _currentframe+1, we advance the movie by 5 frames, changing this to _currentframe-5 makes us go back 5 frames

Creating play and stop buttons are easy, on click or release, either do "stop();"or "play();"

Hope this helps - if you guys have any questions feel free to comment

1 comment:

  1. Thanks Javier! That's a great tip. And very simple (which is perfect).

    ReplyDelete