Making motion using Actionscript*

*ActionScript is a proprietary language developed by Macromedia.

In this tutorial we will construct an elliptical motion using Action Script instead of the tweening functionality. This requires only a few short steps.

  1. Open a new movie. You can easily alter the frame rate, background color, and other features by selecting Modify + Movie (Document in Flash MX). You will obtain the menu

  2. Make a movie clip. This movie clip will become your planet. This is accomplished first by using the circle tool to draw a circle (or ellipse) on the stage. Next choose the Arrow tool and select the circle. Select Insert + Convert and convert the circle to a movie clip. Two of the menus you will see are shown below.

  3. Now here comes an important step. You must give the movie instance a name. First, be sure the Instance panel is open.

    Then from this panel select the Instance tab and type "Planet" into the Name box. We are doing this because we want to address this movie clip with ActionScript. It is an object and all objects must have names if you wish to send it instructions. You will now have something like this:
    You will note that the instance name is different from the movie clip name. This is not only ok but really important in many applications.

  4. In Layer 1 position the cursor in Frame 2 and insert a frame (F5) - not a Keyframe. Do the same in Frame 3. Your Timeline will now look like this.

  5. Next create a new layer. You may give the layer the name: Code. [Layers may be given names by double-clicking on their created name and typing in a new name.] Position the cursor in the first layer. Then type the following action into Frame 1: stop(); Your Timeline will look as follows:

    The Action panel will look something like the image below. The stop() command is inserted to stop the animation until we wish it to begin. If you fail to type this command in the action will start from the loading of the movie. You will need to initiate the timestep however in frame one.

  6. Now select Frame 2 with the mouse and type the code into the Frame Action panel as shown below. This creates the new x and y pixel position of the planet. As you can see, we have the parametric equations for an ellipse.

  7. Now place a Keyframe(F6) in Frame 3 of your Code layer. In the Frame Action box type in the time increment statement and the go to frame 2 statement. The statement, "i = (i+1)%60" will increase the time counter by one but compute the remainer modulo 60. Thus the ellipse will cycle around. (You could as well leave off the "%60.") Now you should have this script.

  8. We are almost done. First create a new layer. Position the cursor in Frame 1 and make a button as before. Do this by drawing a circle or square, choosing the Arrow tool, and selecting the graphic. Then choose Insert + Covert and make the button. Here is the Insert+Covert panel you should see.

  9. Now Choose the button and type in the Object Actions box the following code: i=0;
    gotoAndPlay (2). The "i = 0" statement will initialize the time step. In fact this could be any number - but it must be defined! The Object Action box will look something like this:

  10. You are now ready to test your movie.

  11. Add- ons. On new layers, you can enter text messages, a center of the orbit (e.g. sun), a stop button, another planet. But if you put in another planet, you will need to give it an Instance name and replicate the code for this planet. Change the radius so they don't overlap. You may also alter the motion to just about anything you want. If you use mathematical commands, such as sin, cos, exp, and the like, be sure to refer to them as Math.sin, Math.cos, Math.exp, and so on.

Let's review the process. You needed a movie with an instance name. This is the object you will move around the stage. You needed script to tell the movie what to do. This was placed into a code layer in Frame 2. You then needed script to make a change to the dynamic variable and route the playhead back to Frame 2. Finally, you needed a button to start the planet moving.

Of course you can just start the whole thing by downloading the file ellipse-simple.fla from the URL: Indeed, it you just want to experiment with different motions, this may be the way to proceed.