Stop using mx.transitions.Tween

本文探讨了在Adobe Flash中使用Tweener替代内置Tween类的优势。Tweener提供了更简洁的接口、易于管理和更丰富的缓动选项。文章详细解释了Tween存在的问题,并通过实例对比展示了Tweener的优越性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

zz from:http://www.psyked.co.uk/adobe/flash/stop-using-mxtransitionstween.htm

 

If you’re still using Flash’s inbuilt Tween classes for you scripted animations, I suggest you stop - and start making things easier for yourself by using Tweener instead. Tweener is a class that replaces Tween, works for Actionscript 2 and Actionscript 3, offers a simpler interface for creating tweens, and has a larger range of easing options to work with.

What’s wrong with Tween?

The Tween class is ok - up to a point. It does what it’s supposed to, but once you start trying to integrate it with serious full-on Actionscripting you’ll notice a few snags. If you’re dynamically creating and removing objects, and then want to dynamically modify the tweens, your tweens will likely go crazy. Start a new Tween and there’s very little way you can stop it - even by removing its subject. Stacking Tweens doesn’t go down well either - if you create one to move an object left to right, and then mid-animation another to move it back to the left, things go ok until the point that the first animation should finish - whereupon your object will flick back to the finishing position of the first, and then resume the second animation.

Moreso than that however, is the hassle needed to create an animation with Tween;

import mx.transitions.Tween;


import mx.transitions.easing.*;


var xPosT:Tween = new Tween(myMovieClip, "_x", Bounce.easeOut, 0,
Stage.width, 3, true);


xPosT.onMotionFinished = function() {


// movement finished


};

Why is Tweener better?

First up, there’s no problems with mixing and matching, no misplaced motion crazyness.  You can apply and reapply tweens to your hearts content, and they all work.

Secondly, the interface is simpler - you can setup a tween with less lines of code, and you don’t have to worry about managing objects to execute functions once your tween has run its course. And a single line of code can handle all of the attributes you want changing for a single object - no separate Tween objects for each attribute, just a single Tweener line for all the attributes (on the same object, under the same time and easing style).

import caurina.transitions.Tweener;

Tweener.addTween(myMovieClip, {_x:Stage.width, time:1, transition:"linear",
 onComplete:onCompleteHandler});

function onCompleteHander():Void {
// movement finished


};

Thirdly, you don’t have to worry about things like start variables - just the end variables.  Which makes far more sense.  In most situations I find I’m only adding the current position of an object as the start variable to Tween.  In Tweener, that’s taken as the automatic variable - after all, if you want to set a different position for the object before the tween starts, you just do that on the line above.

Lastly, there’s a invaluable delay attribute.  It’s a built-in timer for your animations - how useful is that!  Want an animation to start after 10 seconds? Easy - just add ‘delay:10′ to your Tweener line.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值