您好我遇到了一个奇怪的问题,因为我试图使用以下代码移动一个MovieClip对象:
TweenLite.from(Dus, 1, { y:- Dus.height ,ease:Cubic.easeOut,alpha:0, onComplete:moveToTopLeftCorner2(Dus)});
public function moveToTopLeftCorner2(mc:MovieClip):void{
trace(mc);
TweenLite.to(mc, .8, {x: 30, y: 40, onComplete:setObjectSmaller2});
}
不幸的是,我上面的代码并没有让MovieClip对象移动到左上角。但我用" trace(mc);"检查了它。查看变量mc中是否有MovieClip对象。所以我检查了" trace(mc);"的输出。它是:
[object MovieClip]
然而,这段代码实际上让MovieClip对象移动到左上角。
TweenLite.from(Dus, 1, { y:- Dus.height ,ease:Cubic.easeOut,alpha:0, onComplete:moveToTopLeftCorner});
public function moveToTopLeftCorner():void{
TweenLite.to(Dus, .8, {x: 30, y: 40, onComplete:setObjectSmaller2});
}
我的问题是:为什么moveToTopLeftCorner2(mc:MovieClip)方法没有将MovieClip对象移动到左上角?而moveToTopLeftCorner()方法确实将MovieClip对象移动到左上角。我还记录了自己向你们展示了MovieClip对象的输出和显示。以下是视频的链接:
答案 0 :(得分:3)
当您说onComplete:moveToTopLeftCorner2(Dus)
时,您将onComplete
值设置为moveToTopLeftCorner2(Dus)
void
的结果。
相反,您只需将其设置为对实际函数的引用:onComplete:moveToTopLeftCorner2
。
您可以使用特殊的onCompleteParams
选项为此函数提供参数,并向其发送一组参数:onCompleteParams: [Dus]
。
TweenLite.from(Dus, 1,
{ y:- Dus.height ,ease:Cubic.easeOut,alpha:0,
onComplete:moveToTopLeftCorner2, onCompleteParams: [Dus]});
public function moveToTopLeftCorner2(mc:MovieClip):void {
trace(mc);
TweenLite.to(mc, .8, {x: 30, y: 40, onComplete:setObjectSmaller2});
}
但是,这有点令人讨厌,因为您必须在代码中指定Dus
两次。相反,您可以使用特殊的"{self}"
参数。
TweenLite.from(Dus, 1,
{ y:- Dus.height, ease:Cubic.easeOut,alpha:0,
onComplete:moveToTopLeftCorner2, onCompleteParams: ["{self}"]});
public function moveToTopLeftCorner2(tween:TweenLite):void {
var mc = tween.target;
TweenLite.to(mc, .8, {x: 30, y: 40, onComplete:setObjectSmaller2});
}
现在,您的onComplete
函数会返回您创建的补间的实例,您可以使用它来访问已补间的对象。