旋转属性的问题

时间:2014-02-14 18:10:29

标签: actionscript-3 button rotation mouse movieclip

我在舞台上有一个名为circle的按钮。移动鼠标时,圆圈指向鼠标。这是我用circle指向鼠标的函数:

stage.addEventListener(MouseEvent.MOUSE_MOVE, followTheMouse);

function followTheMouse(e:MouseEvent):void {
    circle.rotation = Math.atan2(mouseY-circle.y, mouseX-circle.x)*180 / Math.PI + 90;
}

点击circle后,会播放经典补间以将circle移出舞台:

circle.addEventListener(MouseEvent.MOUSE_UP, enterZone);

function enterZone(e:MouseEvent):void {
    this.play();
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, followTheMouse);
}

没有任何编译错误也没有运行时错误。但是,当我点击circle时,它不会离开舞台。

经过一些研究,我了解到旋转属性会导致经典补间动画和补间动画被忽略。为什么会发生这种情况?我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

适合我。您甚至可以启用MOUSE_MOVE事件,它在补间期间可以正常工作。

import flash.display.Sprite;
import fl.transitions.Tween;
import fl.transitions.easing.*;

addEventListener(Event.ENTER_FRAME, loaderCheck);

function loaderCheck(e:Event):void {
    // Make sure we have a populated loader by referencing one of its properties.
    var answer:Boolean;
    try { answer = (this.loaderInfo.width > 0) ? true : false;} catch (e:Error) {}
    if (answer == true) {
        removeEventListener(Event.ENTER_FRAME, loaderCheck);
        createCircle()
    }
}

var circle:Sprite;
function createCircle():void {
    circle = new Sprite();
    circle.graphics.beginFill(0xFF0000);
    circle.graphics.drawCircle(0, 0, 30);
    circle.graphics.drawRect(0, -30, 2, 30);
    circle.graphics.endFill();
    addChild(circle);
    circle.x = loaderInfo.width/2;
    circle.y = loaderInfo.height/2;
    stage.addEventListener(MouseEvent.MOUSE_MOVE, followTheMouse);
    circle.addEventListener(MouseEvent.MOUSE_UP, enterZone);
}

function followTheMouse(e:MouseEvent):void {
    circle.rotation = Math.atan2(mouseY-circle.y, mouseX-circle.x)*180 / Math.PI + 90;
}

function enterZone(e:MouseEvent):void {
    //stage.removeEventListener(MouseEvent.MOUSE_MOVE, followTheMouse);
    var myTween:Tween = new Tween(circle, "x", Elastic.easeOut, 0, 300, 3, true);
}

答案 1 :(得分:0)

经过一番尝试,我设法解决了这个问题。

我所做的是制作一个新的关键帧并在那里放一个按钮的副本,没有实例名称。这样就不会定义rotation属性,并且补间工作正常,因为奇怪的是,movieclip图形属性似乎取消或忽略了用Flash制作的补间。