Jump to content
Search Community

rotateSelection [SOLVED]

wsvdmeer
Moderator Tag

Recommended Posts

Posted

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 :P).

 

private function rotateSelected(value:Number) {	

      //value = -1 or 1

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

    manager.rotateSelection(angle+value)

}

Posted

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

Posted

Hey Jack sorry for my confusing explenation,

 

post-323-133151999615_thumb.png

 

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.

Posted

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));
}

Posted

Hey Jack,

 

That's exactly what i was searching for!

 

Thanks!

  • 2 years later...
Posted

hey,

 

function onClickMinus($e:MouseEvent):void {

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

}

 

flex code ?

 

 

private function myRotate():void{

 

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

}

Posted

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));
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...