Instance action
onClipEvent (enterFrame) {
this._y = this._y + random(3)-1;
this._x = this._x + random(3)-1;
}
addEventListener(Event.ENTER_FRAME, enterFrame);
function enterFrame(event:Event) {
square.y = square.y + int(Math.random()*3)-1;
square.x = square.x + int(Math.random()*3)-1;
}
With this script, the position of the square moves randomly in a horizontal and a vertical direction. The function random(3)-1 (int(Math.random()*3)-1 respectively) generates a random number between -1 and 1. This results in a shivering movement.