Skip to main content
Known Participant
July 24, 2012
Answered

How to rotate a square?

  • July 24, 2012
  • 2 replies
  • 1242 views

hello everyone.

i am trying to rotate a square. for that i used below code.

square.rotation = 90;

this is working fine. But it is working just on one single click..once i have clicked on it it'll rotate. but if i click on it second time it is not rotating.

so how can i do this. can anyone tell me how to do this???

This topic has been closed for replies.
Correct answer Samsimms

//do

//loca is button, loco is movieclip(square)

loca.addEventListener(MouseEvent.CLICK, fStart);

var speed=8;
function fStart(event:MouseEvent):void {
loco.rotation+=speed;
}

2 replies

Ned Murphy
Legend
July 24, 2012

The reason it only worked once is because you were assigning it a fixed value unstead of changing the value each time...

square.rotation = 90;

tells its rotation value to be 90 degrees.  After you reach it the first time, it is at 90 degrees all the time after that.  Instead, to have it change by 90 degrees each time... 

square.rotation += 90;

SamsimmsCorrect answer
Inspiring
July 24, 2012

//do

//loca is button, loco is movieclip(square)

loca.addEventListener(MouseEvent.CLICK, fStart);

var speed=8;
function fStart(event:MouseEvent):void {
loco.rotation+=speed;
}

Known Participant
July 24, 2012

Thanks samsimms..