9.04.2010

[AS3] updateAfterEvent()

Flash 製作鼠標追隨效果時,會發現移動不流暢時,只要加上updateAfterEvent()就能解決此問題。

sample code:
ball1.buttonMode = true;
ball2.buttonMode = true;

ball1.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
ball1.addEventListener(MouseEvent.MOUSE_UP, onUp);
ball1.addEventListener(MouseEvent.MOUSE_MOVE, onMove);

ball2.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
ball2.addEventListener(MouseEvent.MOUSE_UP, onUp);

function onDown(e:MouseEvent):void
{
    e.currentTarget.startDrag();
}

function onUp(e:MouseEvent):void
{
    e.currentTarget.stopDrag();
}

function onMove(e:MouseEvent):void
{
    e.updateAfterEvent();
}

沒有留言:

張貼留言