作者cjcat2266 (CJ Cat)
看板Flash
标题[心得] Tween class的method和event handler补充
时间Wed Jul 25 12:24:01 2007
Tween class的物件还有一些有用的method和event handler
之前打文打太急把它们给忘掉了~XD
本文最後有附上范例
Tween object可以用的method如下:
1.
stop()
将tween motion暂停
2.
resume()
将暂停的tween motion继续执行
3.
continueTo(endValue, duration)
设定新的endValue和duration
4.
fforward()
指定property直接跳到endValue
5.
rewind()
指定property直接跳回startValue
6.
nextFrame()
tween motion(暂停时)往下一个阶段迈进一步
7.
prevFrame()
tween motion(暂停时)往上一个阶段迈进一步
8.
start()
tween motion重新执行一次
9.
yoyo()
tween motion执行完毕的时候,会往回执行
easeIn会自动换成easeOut,反之亦然
Tween object可以用的event handler如下:
1.
onMotionChanged
当指定产生tween motion的property值每一次被更新完後
2.
onMotionFinished
当tween motion执行完毕时(property达到endValue)
3.
onMotionStopped
当使用stop() method来停止tween motion的时候
4.
onMotionResumed
当使用resume() method来继续执行tween motion的时候
5.
onMotionStarted()
当使用start()或者yoyo() method来重新执行tween motion的时候
一开始用new Tween()的时候并不会触发这个event handler
所以我如果要一个场上名为
my_mc的MovieCilp
左右来回震荡
左边界为
10,右边界为
500,半个周期为
2秒,并且在两端点有
平滑减缓效果
我可以写如下的code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var motion:Tween = new Tween(
my_mc,
"_x",
Regular.easeInOut,
10,
500,
2,
true);
motion.onMotionFinished = function(){
this.yoyo();
};
这样可以做出简谐运动的效果
如果不是想要用三角函数参数式进一步操控的话
用这招达成比较省功夫唷~而且写起来比较直觉一点
不用自己算什麽 振幅 周期 中心点 的
("_x =
R*Math.sin(
T) +
D" 的
R,
T, and
D)
只要知道两端点的位置和半个周期长就好了!!!
另外,想要做出斜的简协运动,
只要用两个Tween object在同一个MC上就搞定罗~
(
蓝字为 新增/修改 的code)
import mx.transitions.Tween;
import mx.transitions.easing.*;
var motion:Tween = new Tween(
my_mc,
"_x",
Regular.easeInOut,
10,
500,
2,
true);
var motion2:Tween = new Tween(my_mc, "_y", Regular.easeInOut,10, 500, 2, true);
motion.onMotionFinished = motion2.onMotionFinished = function(){
this.yoyo();
};
如何~?这样不是方便多了吗 =U=+
--
CJ Cat = Croa'J Cat = Cockroach Cat = 西街凯特 = 蜚蠊猫 = 蟑螂猫
Gallery
http://cjcat2266.deviantart.com
MSN
[email protected]
Yahoo
[email protected]
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.228.85.138
※ 编辑: cjcat2266 来自: 61.228.85.138 (07/25 12:25)
※ 编辑: cjcat2266 来自: 61.228.85.138 (07/25 12:46)