ActionScript 3 - 通过补间事件传递事件



我有一个名为"continueMC"的按钮和一个名为"header"的MovieClip。这是我的动作脚本:

continueMC.addEventListener(MouseEvent.CLICK, continueClick);
function continueClick(evt:Event):void {
    fade(header, 0);
}
function fade(evt:MovieClip, fadeTo:Number) {
    var fadeTween:Tween = new Tween(evt, "alpha", Regular.easeIn, evt.alpha, fadeTo, 5, false);
    fadeTween.addEventListener(TweenEvent.MOTION_FINISH, tweenEnd(evt, fadeTo));
}
function tweenEnd(fadeTo:Number) {
    if (fadeTo == 0) {
        trace('here');
        evt.visible=false;
    }
}

我希望影片剪辑在淡入淡出为 0 时变得不可见,但仅在淡入淡出补间完成后。当我单击"继续MC"时,它给出一个错误,说:

here
TypeError: Error #2007: Parameter listener must be non-null.
    at flash.events::EventDispatcher/addEventListener()
    at _flash_file_fla::MainTimeline/fade()
    at _flash_file_fla::MainTimeline/continueClick()

为什么我会收到此错误?

你不能在

addEventListener中将tweenEnd(evt, fadeTo)作为侦听器传递,相反,你可以稍微改变你的tweenEnd方法,以便它正确地接受TweenEvent,然后像这样检查补间的目标:

continueMC.addEventListener(MouseEvent.CLICK, continueClick);
function continueClick(evt:Event):void 
{
    fade(header, 0);
}
function fade(evt:MovieClip, fadeTo:Number) 
{
    var fadeTween:Tween = new Tween(evt, "alpha", Linear.easeIn, evt.alpha, fadeTo, 5, false);
    fadeTween.addEventListener(TweenEvent.MOTION_FINISH, tweenEnd);
}
function tweenEnd(e:TweenEvent) 
{
    /* 
      e.target is the Tween instance
      e.target.obj is the Object that the tween was effecting, in this case,
      it would be "header"
    */
    if(MovieClip(e.target.obj).alpha == 0) 
    {
        trace('here');
        MovieClip(e.target.obj).visible=false;
    }
}

相关内容

  • 没有找到相关文章

最新更新