5/2/2006
Tween class and onMotionFinished
最近一个项目中又用到了Tween类,并且遇到一个棘手问题,就是Tween类的onMothionFinished函数中无法调用其他的函数及对象。谷歌了一下,国内很少有人提,但是无人解决,到底还是老外牛,让我找到了答案,原来是作用域的问题,解决办法是用Delegate类来保持作用域。
eg.
-----------------------------------------------------------------------------------------------------------
import mx.utils.Delegate;
public function changeImage( button:MovieClip ):Void
{
...
stripTween.onMotionFinished = Delegate.create(this, onStripTweenFinished);
}
public function onStripTweenFinished():Void
{
this.currentButton.enabled = true;
}
-----------------------------------------------------------------------------------------------------------
如果是单纯的想访问一个变量/对象,也可以使用这种形式:
-----------------------------------------------------------------------------------------------------------
stripTween = new Tween ( strip, "_y", Strong.easeOut, strip._y, nextPlace, 1, true);
stripTween .currentButton=this.currentButton;
stripTween.onMotionFinished = function( )
{
this.currentButton.enabled = true;
};
-----------------------------------------------------------------------------------------------------------