CS 325 and Film 385: Introduction to Flash Scripting

flash icon

Highlights of this lab:

  • What is ActionScript?
  • Controlling the Timeline
  • Button Navigation
  • Scripted Navigation
  • Showing Messages & Text Controls
  • Controlling Media
  • Adding Your Flash Movie to an existing Webpage (time permitting)
  • Assignment

:: What is ActionScript? ::

ActionScript is the programming language that is used to control, or script, Flash animations. Some of the design tools in Flash generate ActionScript for you, but for most tasks you will have to write it for yourself. With ActionScript you can control the flow of an animation, give Symbols "intelligent" behaviour, interact with the user, make a game, or connect to a database. You've probably already seen many examples of what can be done. Last week you used it to make a button that went to a web page. In this week's lab we will take a better look at how to do write ActionScript.

The most recent version of ActionScript is ActionScript 3.0. This is a mature and capable programming language. Earlier versions of ActionScript were cobbled together as Flash programmers requested new features and as Macromedia, then Adobe, added them to Flash. For very simple tasks, ActionScript 1 and 2 are probably simpler to use. However, for very large jobs they are inefficient and hard to manage. It is well worth the effort for any programmer who is new to Flash Scripting to begin with ActionScript 3.0 despite the learning curve.

:: Controlling the Timeline ::

There are four functions you can use to control the timeline. You will see one of them in the this section and two in the next:

gotoAndPlay( frame )
This function jumps to a frame and starts the timeline playing at that point. Any ActionScript in the frame after this function is skipped, so be careful. The frame can be a number or a text label.
gotoAndStop( frame )
This function is exactly like gotoAndPlay, except that the playhead is stopped after the jump.
Stops the playhead and the animation, but not ActionScript.
Starts the playhead, resuming animation.

:: Button Navigation ::

The buttons in frame 1 and frame 31 still don't do anything. We need to give them something to do:

:: Scripted Navigation ::

Now that the animation doesn't repeat and flicker so much it is much improved. However we can do better. We can repeat the jumping jacks section by creating what programmers call a loop. This loop will be a count controlled loop. We will store a number, change it everytime the jumping jack animation finishes and keep repeating the animation until we reach our goal of 5 jumping jacks..

First we need to set up the number:

Then we need to keep counting up and going back until we reach 5:

Run the program and try the Repeat button. How many times do the jumping jacks repeat? Can you guess why?

Let's fix that:

:: Showing Messages & Text Controls ::

Up until now if you put text into your flash animation it was "static". It didn't change unless you created a keyframe and added a new text box. With ActionScript you can change the text in a specially formatted text box:

Challenge: The way the animation is set up you can't see the number 5. See if you can update the number in the middle of the jumping jack and make the number 5 visible briefly.

:: Controlling Media ::



:: Making Your Published Flash Movie Customisable ::

You can use parameters to load customs songs or movies, or have a custom message in your published Flash file.

I will show you how to use the published HTML file to load a different song into the song player. We will load the Windigo.mp3 song that is in the MP3 folder beside the song we are already using. These instructions will work with both the simple and the advanced player.

Here are the steps:

  1. ask for a list of parameters that were sent in from the web page
  2. when you are setting up the customizable elements on in ActionScript, find out if a related parameter was used:
  3. Publish your project. When you load the HTML page and get to the song it should play the default song.
  4. Edit the HTML file.

:: Assignment ::

For this lab assignment I want you to simply follow the instruction for this lab and create a flash animation or button. The animation or button can be exactly as descibed above.

Embed your flash file on your web page if you like, but please submit your flash .fla document, your published .html and .swf files, and all your resources in a folder with your name on it. This is due at the beginning of your next lab. Have fun!

..:: Web [Re]Sources ::..

..:: Other References ::..