Back to Bluesfear
Digital Art

Flash - Action Script Motion
Written by Chris aka Solaris

As all you know already, actionscript is used for backend operations and movie controls. And motion is defined generally by tweening. While this is the most commonly used way to generate motion, this tutorial will show you simple and effective ways to use actionscript to make motion.

Making actionscript induced motion isn't too complicated. First off, make a new doc. The size doesnt matter, and bg color doesnt either. Pick a frame rate of 20 anyway. This makes the movie appear less "choppy" as it would with 12 fps. Create an object, preferably a square. After you have finished, convert to a movie clip. Open the actions panel for that MC, and copy and paste this code into it:


 
onClipEvent (enterFrame)
{
this._rotation+=1;
}

 

Notice how this code makes the movie clip move right? The number 1 specifies how many degrees to move each frame. Now try changing the + to a -. So now it should like this:

  onClipEvent (enterFrame)
{
this._rotation-=1;
}

 

Now it moves, but this time to the right. Changing the number will change the degrees in which it rotates.

Now a more complicated but still simple to understand script would be to apply these rotations randomly. And also at different speeds. To do this replace the original script with this one:


  onClipEvent (enterFrame) {
    if (this._rotation == 0) {
        rotateIncrement = .1;
    }
    if (rotateIncrement<=1) {
        accelFlag = 1;
    }
    if (rotateIncrement>30) {
        accelFlag = 0;
    }
    if (accelFlag == 1) {
        rotateIncrement = rotateIncrement*1.1;
    }
    if (accelFlag == 0) {
        rotateIncrement = .1;
    }
    this._rotation += rotateIncrement;

}



This chooses increments at which to randomly speed up the mc and slow down too. Now lets do a more complicated procedure that resembles this one but is more visually appealing. Replace the whole script with this one:

  onClipEvent (enterFrame) {
    if (this._rotation == 0) {
        rotateIncrement = .1;
    }
    if (rotateIncrement<=.1) {
        accelFlag = 1;
    }
    if (rotateIncrement>20) {
        accelFlag = 0;
    }
    if (accelFlag == 1) {
        rotateIncrement = rotateIncrement*1.1;
    }
    if (accelFlag == 0) {
        rotateIncrement = rotateIncrement*.9;
    }
    this._rotation += rotateIncrement;
}


Now you see it rotates the MC but this time it speeds up and then decellerates as well. You should note that it does this randomly. Thanks for your time. Hope you learned alot!

(back to Bluesfear)      
2000, 2004© BlueSfear