Dakular's profile打哭了的拨烙锅PhotosBlogLists Tools Help

Blog


    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;
     };

    -----------------------------------------------------------------------------------------------------------
     
     
     
     

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://dakular.spaces.live.com/blog/cns!8668FFEC49BC51CE!366.trak
    Weblogs that reference this entry
    • None