开发者

ActionScript - Serious Performance Problem Using TweenLite & Mouse Move Event

i'm receiving a very noticeable performance hit when using TweenLite to tween a filter while dragging.

private function mouseMoveEventHandler(evt:MouseEvent):void
    {
    evt.stopImmediatePropagation();

    startDrag();

    zoomTween = new TweenLite(this, 1.0, {dropShadowAmount: ZOOM_SHADOW, scaleX: 1.5, scaleY: 1.5, rotation: 10, onUpdate: updateDropShadow, onComplete: completeDropShadow, onCompleteParams: [ZOOM_SHADOW]});

    removeEventListener(MouseEvent.CLICK, mouseClickEventHandler);
    addEventListener(MouseEvent.MOUSE_UP, mouseUpEventHandler);
    addEventListener(MouseEvent.MOUSE_OUT, mous开发者_运维知识库eUpEventHandler);
    }

private function updateDropShadow():void
    {
    filters = [new DropShadowFilter(dropShadowAmount, 90, 0x000000, 1.0, dropShadowAmount * 2, dropShadowAmount * 2, 1.0, 3)];
    }

private function completeDropShadow(dropShadowAmount:Number):void
    {
    this.dropShadowAmount = dropShadowAmount;
    }

i understand there is a Drop Shadow Plusing with TweenLite, but that only has the ability to tween the filter on and off, rather than change the distance or blur amount of an always visible drop shadow.

also, i'm not testing this on a mobile phone, i'm testing on my fast desktop in both Flash CS5 and the external debugger - both are lagging the display object, which is just a simple square shape, even after the zoomTween has completed.

any ideas?


You're instantiating a new TweenLite on every mousemove update. You can potentially have dozens of those happen all within the space of a single enter_frame interval. That's potentially a lot of TweenLite instances, all trying to move the same object at the same time for one second. Think hundreds of them for just a "short" mouse movement. Thousands for extended motions.

For mobile especially, you need to avoid mousemove events, as they absolutely flood the system. It's data overload. Perhaps instead you could track the change in delta over time in an enter_frame or timer event handler? Do that, and then assure that only one tweenlite exists at a time (kill the old one, or just let the old one finish before assigning a new one).

Also note that filters are going to be really hard on your mobile device. You may get this up and running on desktop, but I'd be surprised if it works out on mobile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜