onClipEvent (enterFrame) {
if (this._x<500&&this._x.0) {
this._x=this_x + Math.random()*100;
}
if (this._x>=500) {
this._x=this_x - Math.random()*500;
}
if (this._y<400&&this._y.0) {
this._y=this_y + Math.random()*100;
}
if (this._y>=400) {
this._y=this_y - Math.random()*400;
}
}
That looks rather staggering and confusing, but its not. If you break it down line by line, its saying this:
If the horizontal position of my object is less than the width of my movie (in my case, 500 pixels) but greater than 0, then generate a random number, multiply it by 100, and advance the horizontal position of my object to the right by that amount. If, however, the horizontal position is greater than or equal to the width of my movie, then generate a random number, multiply it by the width of my movie, and then subtract that from my objects current horizontal position to move it back by that many pixels.
It works similarly for the y (vertical) position. You can look here for my example.


