Question

I have a button called circle on stage. When the mouse is moved, the circle points to the mouse. This is the function I used to make circle point the mouse:

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

When circle is clicked, a classic tween plays to move circle out of the stage:

circle.addEventListener(MouseEvent.MOUSE_UP, enterZone);

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

There aren't any compilation errors nor runtime errors. However, when I click the circle, it doesn't move away from the stage.

After some research, I've learnt that the rotation property causes classic and motion tweens to be ignored. Why does this happen and how can I fix this?

Was it helpful?

Solution 2

After some tries, I managed to solve this problem.

What I did was to make a new keyframe and put a copy of the button there, with no instance name. This way the rotation property won't be defined, and the tween works normally, since strangely, the movieclip graphic properties seem to cancel or ignore the tweens made with Flash.

OTHER TIPS

Works for me. You can even leave the MOUSE_MOVE event on and it works during tweens.

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top