New2AS3
New2AS3

Reputation: 36

Only rotate last clicked MovieClip

I have a project where a MovieClip gets copied when clicked and dragged. It is also possible to rotate and scale the MovieClip with arrow keys.

But this only rotates last MovieClip dragged, not last MovieClip clicked. So if I drag a new copy, the previous dragged copies are not able to rotate or scale.

How can I change this to only make the last MovieClip clicked able to rotate and scale, when arrow keys are pressed?

Here is some of the code used (taken and slightly modified from another post):

addEventListener(Event.ENTER_FRAME, moveObject);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);
stage.addEventListener(KeyboardEvent.KEY_UP, noKeyHit);


function keyHit(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT) leftArrow = true;
if(e.keyCode == Keyboard.RIGHT) rightArrow = true;
if(e.keyCode == Keyboard.UP) upArrow = true;
if(e.keyCode == Keyboard.DOWN) downArrow = true;
}


function noKeyHit(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT) leftArrow = false;
if(e.keyCode == Keyboard.RIGHT) rightArrow = false;
if(e.keyCode == Keyboard.UP) upArrow = false;
if(e.keyCode == Keyboard.DOWN) downArrow = false;
}


function moveObject(e:Event):void{
if(leftArrow) latestClone.rotation -=0.75;
if(rightArrow) latestClone.rotation +=0.75;
if(upArrow) latestClone.scaleY +=0.01
if(downArrow) latestClone.scaleY -=0.01;
} 

Thank you

Upvotes: 0

Views: 37

Answers (1)

zlumer
zlumer

Reputation: 7004

In your code you are scaling and rotating latestClone.
Somewhere outside of this code you are setting the value of latestClone.
If you want to rotate the latest clicked MovieClip, add an event listener to the click:

latestClone.addEventListener(MouseEvent.CLICK, onCloneClick);
function onCloneClick(e:MouseEvent):void
{
    var target:MovieClip = e.currentTarget as MovieClip;
    latestClone = target;
}

Upvotes: 1

Related Questions