Saturday, July 12, 2008

Learning the Basics

This tutorial will cover a few of the most basic functions of actionscript. One of the most used set of functions, and most commonly forgotten to mention in tutorials due to everyone assuming everyone else knows them is the gotoAnds. There are two main functions in this set: gotoAndStop() and gotoAndPlay(). Each of these is used to seek and and either stop at or play from a frame in the timeline.
For example, if you wanted a movie to goto the 5th frame and stop there from frame 1 you'd put _root.gotoAndStop(5) in the actions for the first frame (the actions panel can be accessed by pressing f9 or clicking on the actions tab near the bottom of the screen right above the properties tab, make sure it says actions -- frame rather than actions -- button or some such).
Likewise, you can also use stop() and play() by themselves on frames. For example if you had an animation that played for 200 frames, and you didn't want it to loop, you could simply put a stop() action on the 200th frame. Another sometimes useful set of functions is the nextFrame() and prevFrame(). These go one frame ahead or forward, respectively.
Now, if you want to use all these actions, here's a good way. You can make a play/pause/forward/back menu type thing for an animation. To do so simply add a new layer to your timeline that has blank non-keyframes until the end of your movie, or where you want there not to be buttons. Then draw a play, pause, forward, and back buttons. To convert them into buttons just select one of them and press f8. This should pop up a convert to symbol window. Be sure that "button" is selected. Then apply these actions to each button, respectively:

play button:

on(release){
_root.play()
}



pause button:

on(release){
_root.stop()
}



forward button:

on(release){
_root.nextFrame()
}



back button:

on(release){
_root.prevFrame()
}



In each case the _root. element means that the root, or base timeline, will follow that action. The on(release){ part means that what's in the brackets is what will happen when the button is released.
Here's an crappily sketched example.swf:




No comments: