Skip to main content
jeffery wright
Inspiring
November 7, 2013
Answered

Click, animate rotation of Object by +90° via AS3?

  • November 7, 2013
  • 1 reply
  • 3157 views

I have a button that will rotate an object in its parent by 90 degrees every time its clicked:

b_rotate_CW.addEventListener(MouseEvent.CLICK, rotateCW);

function rotateCW(event:MouseEvent):void

{

Object(this).parent.module.rotation += 90;

}

Which is fine, but I think it would be a nice touch if the object's rotation were animated.

I tried this:

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

b_rotate_CW.addEventListener(MouseEvent.CLICK, rotateCW);

function rotateCW(event:MouseEvent):void

{

var rCW:Tween = new Tween(Object(this).parent.module, "rotate", Strong.easeOut, 0, +90, .5, true);

}

... but it does nothing at all, I am guessing that "rotate" is a property option, I can find no documentation for that, only x, y, their scale and alpha.

I'm sure this has been done by many, can anyone offer a helpful clue as to how this function would be properly coded?

Thanks!

This topic has been closed for replies.
Correct answer jeffery wright

Thats brilliant, I tweaked it a little; replaced the 0 with the current angle of the clip) and now it works perfectly:

var rCW:Tween;

b_rotate_CW.addEventListener(MouseEvent.CLICK, rotateCW);

function rotateCW(event:MouseEvent):void

{

rCW = new Tween(Object(this).parent.module, "rotation", Strong.easeOut, Object(this).parent.module.rotation, Object(this).parent.module.rotation+90, .5, true);

}

Who would have known you could use a target path in place of a value?

Where can everyone learn AS3 as you know it?

Thank you again for your immense help!

1 reply

kglad
Community Expert
Community Expert
November 7, 2013

use:

import fl.transitions.Tween;

import fl.transitions.easing.*;

import fl.transitions.TweenEvent;

var rCW:Tween;

b_rotate_CW.addEventListener(MouseEvent.CLICK, rotateCW);

function rotateCW(event:MouseEvent):void

{

rCW = new Tween(Object(this).parent.module, "rotatation", Strong.easeOut, 0, Object(this).parent.module.rotation+90, .5, true);

}

jeffery wright
jeffery wrightAuthorCorrect answer
Inspiring
November 11, 2013

Thats brilliant, I tweaked it a little; replaced the 0 with the current angle of the clip) and now it works perfectly:

var rCW:Tween;

b_rotate_CW.addEventListener(MouseEvent.CLICK, rotateCW);

function rotateCW(event:MouseEvent):void

{

rCW = new Tween(Object(this).parent.module, "rotation", Strong.easeOut, Object(this).parent.module.rotation, Object(this).parent.module.rotation+90, .5, true);

}

Who would have known you could use a target path in place of a value?

Where can everyone learn AS3 as you know it?

Thank you again for your immense help!

kglad
Community Expert
Community Expert
November 11, 2013

you're welcome.