Degrees Flash Rotate

Posted by admin in Flashes | No comments






Degrees Flash Rotate
How do I make a flash object in a fixed position rotate to follow the mouse direction?

What I'm aiming for is an object that remains in a fixed position but rotates to face the mouse pointer's current location. I would also like to limit the rotation degree if possible.

I'm completely new at Flash; tutorials or code examples would be greatly appreciated. Thanks!

Use geometry.

I'm just going to assume you're using Actionscript 2. Actionscript 3 should probably come with a similar approach but with slightly different syntax.

You have both the coordinates of your object and the mouse:
The object's coordinates can be called using objectinstancename._x and objectinstancename._y.
The mouse coordinates can be called using this._xmouse and this._ymouse Using a simple tangent rule (find some info on Math.tan in the first source) you could calculate the angle between the object and your mouse.

The next thing you'd have to do is use objectinstancename._rotation = angle to turn the object towards the proper angle. That's all!

Obviously you would have to redo these calculations every time the mouse moves, so wrap it up inside an onMouseMove event. (info in source 2)



Items Recently Purchased From This Site:

Flash Bracket with 90 Degrees Flash Rotate feature, Flash Bracket with 90 degrees Camera Rotate feature,
Powered by phpBay Pro

 


Leave a comment

Please sign in to leave a comment.