1. Home
  2. Computing & Technology
  3. Animation

Animating with ActionScripts

By , About.com Guide

6 of 7

The previous script will work if you just want your object to move once; the Flash movie won’t recognize the far/right edge of the stage, so the object will just keep moving and the ActionScript will keep cycling long after it’s out of sight, unless we add some kind of conditions to determine when it should stop moving the symbol. For that we can use an if statement, inserted inside the onClipEvent(enterFrame) and nested outside of the this._x=this._x+5:

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

For the condition of my if statement, I’ve told Flash that it’s only supposed to move my symbol to the right by 5 pixels if its current center point’s position is less than or equal to 625 pixesl from the left edge of the stage. This prevents the symbol from moving any farther beyond x coordinate 625.

Explore Animation
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.