Search In
• More options...
Find results that contain...
Find results in...

# rotateSelection [SOLVED]

## Recommended Posts

Hi Jack,

I'm having a problem rotating a selected item when i use the following code.

How can i get the rotation right? ( is suck at math ).

private function rotateSelected(value:Number) {

//value = -1 or 1

var angle:Number = Math.atan2(currentTarget.x,currentTarget.y)

manager.rotateSelection(angle+value)

}

##### Share on other sites

Sorry, but I have no idea what you're trying to accomplish so I can't help with the Math. Please explain.

##### Share on other sites

Hey Jack sorry for my confusing explenation,

I have a transformItem on the stage and 2 buttons one for rotating the object left( - ) and one for rotating the object right( + ).

When i push one of the buttons the function rotateSelected is fired and i get a variable called "value"

Button "Left" gives a value of -1 wich indicates that the transformItem has to rotate counter clockwise.

Button "Right" gives a value of 1 wich indicates that the transformItem has to rotate clockwise.

In short i want the user to rotate the object with the buttons.

I know this is possible by calling TransformManager.rotateSelected("angle")

But i have no idea on how to get the right value for the angle.

##### Share on other sites

It should be relatively straightforward as long as you realize that rotateSelection() accepts RADIAN values, not degrees

If you want to translate degrees to radians, you'd just do:

var radians:Number = degrees * (Math.PI / 180);

So if you want it to rotate 5 degrees, have your + button call a function like:

function onClickPlus(\$e:MouseEvent):void {
myManager.rotateSelection(5 * (Math.PI / 180));
}

And your - button could call something like:

function onClickMinus(\$e:MouseEvent):void {
myManager.rotateSelection(-5 * (Math.PI / 180));
}

##### Share on other sites

Hey Jack,

That's exactly what i was searching for!

Thanks!

##### Share on other sites

• 2 years later...

hey,

function onClickMinus(\$e:MouseEvent):void {

myManager.rotateSelection(-5 * (Math.PI / 180));

}

flex code ?

private function myRotate():void{

............?

}

##### Share on other sites

The Flex code wouldn't really be different. And it depends on what you named your FlexTransformManager instance.

private function myRotate():void{
myManager.rotateSelection(-5 * (Math.PI / 180));
}

Thank u