Question
AS3 - removeEventListener
Hi there.
Got this code that creates a sprite.
Need to make it follow the mouse on MOUSE_DOWN and stop on MOUSE_UP.
Problem is that I can't stop the MOUSE_MOVE Listener given to the stage.
Any Help...?
Here is my code:
import gs.TweenLite;
import fl.motion.easing.*
this.stop ();
function addCircle ( _sp:Sprite, x:uint, y:uint, radius:uint ):void
{
_sp.graphics.clear ();
_sp.graphics.beginFill(0x666666);
_sp.graphics.drawCircle(x, y, radius);
_sp.graphics.endFill();
}
var sp:Sprite = new Sprite();
addCircle (sp, 0, 0, 20);
stage.addChild(sp);
function moveSprite ( _sp:Sprite ):void
{
TweenLite.to(_sp, 1,
{
x:mouseX,
y:mouseY,
ease:Sine.easeOut
});
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void {
moveSprite (sp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, function ():void {
moveSprite (sp);
});
});
stage.addEventListener(MouseEvent.MOUSE_UP, function ():void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveSprite);
});
Thanks