Adobe Flash Cs3 Tutorials
Adobe's CS3 was the first in the Flash versions to introduce ActionScript 3.0 compared with its predecessors, which were using ActionScript 2.0. Although 2.0 is still supported and in wide use today, it is slowly being marginalized by acceptance of the 3.0 language which is, in some ways only slightly different. You can use either 2.0 or 3.0 code in CS3 or the more recent Flash CS4, but certain features of the program will only work if you code in 3.0.
-
The "Stop" Command
-
Screen-recording software is required. ActionScript are the commands that control the timeline. With CS3 open, your timeline extends across the first visible layer, stretching toward infinity. Right now, there is only one keyframe in that layer, so if you tested your movie, nothing would happen because there are no other frames for Flash to go to. Right click on frame 40 and choose "insert Keyframe" from the menu. Now if you tested your movie the movie would start at frame 1 and play to frame 40 then start over, looping indefinitely.
Right click on keyframe 20 and insert a keyframe there as well. Then with the keyframe selected, press "F9" on your keyboard to bring up the actions panel. In the actions panel type:
"stop()"
without the quotes. This will cause the playhead in your movie to play from frame 1 to 20 and when it reaches 20, it will stop the movie and do nothing else.
Event Listener
-
If you wanted to get your movie going again, you would have to use the "play()" command, but putting that on the keyframe after "stop()" would essentially negate your "stop()" in the first place. Let's add a quick button on the stage in keyframe 20 that a user could press to get the movie going again. First add an EventListener, which will "listen" to the button and wait for it to do something:
Use the drawing tools to create a button on the stage. Press "F8" to turn it into a symbol and name it whatever you want. Give it an instance name in the Properties Inspector of "myButton" so that the ActionScript may work on it.
Select the keyframe itself (not the button) and press "F9" to bring up the actions panel and type in this code without the quotes:
"myButton.addEventListener(MouseEvent.CLICK, startMovie);"
This tells flash to "listen" to "myButton" to see if it is ever CLICKed. And if it is, to run the function called "startMovie" which we will write next.
-
"Play" Command
-
Beneath the code typed above, which tells Flash to run a function "startMovie" whenever your button is clicked, type in the following code, again, without quotes:
"function startMovie(event:MouseEvent):void
{
play();
}"This code creates a function called "startMovie" that simply starts the playhead running again. Your movie will continue playing from wherever it is.
"gotoAndPlay" command
-
There are times in Flash you will want a button to cause the movie to jump to a specific frame or scene in the movie and continue playing from there. Instead of using "play()" you would use "gotoAndPlay()" and inside the parenthesis, you put the scene name (in quotes) or the frame number (without quotes) that you want the movie to go to. For example, change the "play()" command in the function you've created to "gotoAndPlay(30)" Insert a new keyframe on 30 and put an object (text, drawing, whatever) on the stage so you can see once you've reached keyframe 30 and test your movie.
Alternatively, you can also use "gotoAndStop()" to make your movie jump to a frame and stay there.
The "Timer"
-
One of the best things about a well designed Flash movie is that some things seem to happen automatically or in sequence. One way of doing this is timers, bits of code (functions) designed to go off at a specific interval set by you. Paste the following code below your EventListener and function.
"var eggTimer:Timer = new Timer(8500, 1);
eggTimer.addEventListener(TimerEvent.TIMER, egg);
function egg(event:TimerEvent):void
{
gotoAndStop(30);
}
eggTimer.start()
"This code creates a timer and names it "eggTimer"--though you can call it what you want, and says that in 8.5 seconds, run the function called "egg"
"egg" tells the movie to gotoAndStop frame 30. The last bit of code "egtTimer.start() starts the counter on the Timer running. Without that last line nothing would happen. Test your movie, and you should see that when you reach frame 20, if you don't press the play button in 8.5 seconds, the movie will jump to frame 30 without you.
Tying it All Together
-
Various functions and snippets of code in this tutorial are only a very basic beginning to ActionScript 3.0. They can be taken, modified and used in literally hundreds of ways to create interactive movies, websites or training programs. Keep playing with them and trying different things is the one of the best ways of learning. If you get something to work, save your file in a new name with a description of what the code is doing. This way also, if you do something that "breaks" your code and it no longer works, you can go back to something that works.
-
References
Resources
- Photo Credit Image by Flickr.com, courtesy of : (Halid Said Altuner Image by Flickr.com, courtesy of Tim Dorr