仅旋转最后单击的MovieClip

时间:2016-02-12 10:28:55

标签: actionscript-3 flash

我有一个项目,在点击和拖动时会复制MovieClip。也可以使用箭头键旋转和缩放MovieClip。

但是这只会旋转最后一个MovieClip,而不是最后一个MovieClip点击。因此,如果我拖动新副本,之前拖动的副本将无法旋转或缩放。

当按下箭头键时,如何将其更改为仅使点击的最后一个MovieClip能够旋转和缩放?

以下是一些使用过的代码(从另一篇文章中采取并稍作修改):

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

谢谢

1 个答案:

答案 0 :(得分:1)

在您的代码中,您正在缩放并轮换latestClone 在此代码之外的某处,您设置的值为latestClone 如果要旋转最新单击的MovieClip,请向单击添加事件侦听器:

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