1. Home
  2. Computing & Technology
  3. Animation

Dynamic Animation in Flash: Moving Dynamically Drawn Shapes

By , About.com Guide

7 of 7

To create a more random animation that makes the box jump all over the screen like someone put itching powder in its pants, set constraints for the motion using the width and height of the stage as maximum allowable values, in which a random value between 0 and the width/height is added to the current x and y position as long as either stays below the max – while when it reaches the max, instead a random value between 0 and a chosen number is subtracted.
onClipEvent (enterFrame) {
if (_root.box._x<300&&_root.box._x>0) {
_root.box._x=_root.box_x + Math.random()*300;
}
if (_root.box._x=300) {
_root.box._x=_root.box_x - Math.random()*75;
}
if (_root.box._y<300&&_root.box._y>0) {
_root.box._y=_root.box_y + Math.random()*300;
}
if (_root.box._y=300) {
_root.box._y=_root.box_y - Math.random()*75;
}
}
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. Dynamic Animation in Flash: Moving Dynamically Drawn Shapes

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

All rights reserved.