Actually this one is about _rotation, since AS2 is main subject. In AS3 underscore is gone. Some functions I’ll be using here are also deprecated in AS3 since they are included in built-in classes. Easiest way to use _rotation is to name your mc instance, say box1 and create this function:
onEnterFrame = function(){ box1._rotation += 10;}
On every new frame box1 will rotate 10 degrees clockwise. All values from 0 to 180 will rotate clockwise direction and negative values from 0 to -180 will rotate counterclockwise. Values out of range will also work like they are normalized to given interval. Sure, this is boring. To give it some more action, try to make rotation as function of mouse position. Use next code:
var speed:Number;
onEnterFrame = function(){ speed = _xmouse - box1._x; box1._rotation += speed / 10;}
Variable speed is distance from mouse x position and our box1 movie clip. If mouse has grater x than box movie clip, speed variable is positive value and if mouse has smaller x value than box movie clip, speed value is negative and rotation is counterclockwise. If only one direction is needed we use Math.abs method to find distance and since it produce only non-negative values, rotation is always in clockwise direction.
var speed:Number;
onEnterFrame = function(){ speed = Math.abs(_xmouse - box1._x); box1._rotation += speed / 10;}
We divide speed with 10 to get reasonable values for rotation. If we skip this step speed can be up to half of Stage width, 200 or more and box will rotate too fast.
download example
- to be continued -