1. Home
  2. Computing & Technology
  3. Animation

Animating with ActionScripts

By Adrien-Luc Sanders, About.com

5 of 7

We’ve set the when, now we need to set the what:

onClipEvent (load){
this._x = 10;
}
onClipEvent (enterFrame) {
this._x = this._x+5;
}

Before we said that this._x (the current symbol’s horizontal position) was at a point 10 pixels from the left side of the stage; now we’re telling Flash that each time it enters that frame, it needs to check to take the position of the symbol and add 5 pixels to it, moving it 5 pixels to the right. That’s sliding 60 pixels per second, because rather than resetting, it instead builds on itself. To simplify:

Say we’re working on twelve frames instead of one. We’ll call the position of the symbol P.

Frame 1: P=10; P=P=5, or P=10+5, so P=15.
Frame 2: P=P+5, or P=15+5, so P=20.
Frame 3: P=P+5, or P=20+5, so P=25.
Frame 4: P=P+5, or P=25+5, so P=30.
Frame 5: P=P+5, or P=30+5, so P=35.
Frame 6: P=P+5, or P=35+5, so P=40.
Frame 7: P=P+5, or P=40+5, so P=45.
Frame 8: P=P+5, or P=45+5, so P=50.
Frame 9: P=P+5, or P=50+5, so P=55.
Frame 10: P=P+5, or P=55+5, so P=60.
Frame 11: P=P+5, or P=60+5, so P=65.
Frame 12: P=P+5, or P=65+5, so P=70.

So at the start of one second, position P was 10 pixels away from the left edge of the stage; at the end of one second/12 frames, P had cycled through the ActionScript so many times that P is now 70 pixels away from the left edge of the stage.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Animating with ActionScripts

©2009 About.com, a part of The New York Times Company.

All rights reserved.