为什么我在这里收到“参数计数不匹配”错误?

时间:2010-04-11 19:50:09

标签: flash actionscript-3 function arguments

我有一个Document类,简介类和导航类。

首先运行简介类,然后发送自定义调度事件来运行导航类,但我收到此错误:

removed Intro
ArgumentError: Error #1063: Argument count mismatch on com.secrettowriting.StanPlayer.ui::Navigation/addNav(). Expected 0, got 1.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.secrettowriting.StanPlayer.display::Intro/removeIntro()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

Navigation类中的addNav函数应该需要0个参数/变量,我不会向它发送任何参数/变量,这就是为什么我为什么说它得到1而感到困惑。

(1)此操作会附加完整的侦听器

private function drawIntro():void
{
    intro = new Intro();
    intro.drawIntro();
    intro.addEventListener("onComplete", nav.addNav);
    stage.addChild(intro);
}

(2)在Intro类中,此函数将命中并发送dispatch事件,但我在trace语句后立即收到该错误。

private function removeIntro(e:TimerEvent):void
    {           
        if (n < 10){
            n++
        } else if (n == 10){
            introRemover.removeEventListener(TimerEvent.TIMER, removeIntro);
            removeChild(introMov);
            trace("removed Intro");

            dispatchEvent (new CustomEvent(CustomEvent.COMPLETE, {})); // → Intro to Navigation
        }
    }

(3)然后假设在导航

中触发此功能
public function addNav():void
    {
        trace("addNav ----");
        addChild(weAreA);
        addChild(introText);
        addChild(chooseAVideo);

        TweenLite.to(weAreA, 2, {alpha:1});
        TweenLite.to(introText, 3, {alpha:1});
        TweenLite.to(introText, 3, {alpha:1});
    }



类代码--------------------------------------------- -----------------

我的文档类:

    public function HomePlayer():void
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align     = StageAlign.TOP_LEFT;

        // Use when Live
            //videoURL = this.loaderInfo.parameters.theVIDEO; // Get the Video URL from HTML

        // Remove when video testing ready
            videoURL = "videos/WhatDifferentiatesUs.flv";

        drawNav();
        drawIntro();
    }

    private function drawIntro():void
    {
        intro = new Intro();
        intro.drawIntro();
        intro.addEventListener("onComplete", nav.addNav);
        stage.addChild(intro);
    }

    private function drawNav():void
    {
        nav = new Navigation();
        nav.drawNav();
        stage.addChild(nav);
    }


简介类:

    Public function Intro():void
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
    }

    public function drawIntro():void
    {           
        introMov       = new IntroMov();
        introMov.alpha = 0;

        addChild(introMov);

        TweenLite.to(introMov, 3, {alpha:1});

        // Timer
        introFader = new Timer(INTRO_DELAY);
        introFader.addEventListener(TimerEvent.TIMER, fadeIntro);
        introFader.start();

        introRemover = new Timer(INTRO_DELAY);
        introRemover.addEventListener(TimerEvent.TIMER, removeIntro);
    }

    private function fadeIntro(e:TimerEvent):void
    {
        if (i < 30){
            i++
        } else if (i == 30){
            TweenLite.to(introMov, 1.5, {alpha:0});
            introFader.removeEventListener(TimerEvent.TIMER, fadeIntro);
            introRemover.start();
        }
    }

    private function removeIntro(e:TimerEvent):void
    {           
        if (n < 10){
            n++
        } else if (n == 10){
            introRemover.removeEventListener(TimerEvent.TIMER, removeIntro);
            removeChild(introMov);
            trace("removed Intro");

            dispatchEvent (new CustomEvent(CustomEvent.COMPLETE, {})); // → Intro to Navigation
        }
    }


导航类功能:

  public function drawNav():void
    {           
        weAreA       = new WeAreA();
        weAreA.alpha = 0;
        weAreA.x     = 20;
        weAreA.y     = 35;

        introText       = new IntroText();
        introText.alpha = 0;
        introText.x     = 20;
        introText.y     = 124;

        chooseAVideo       = new ChooseAVideo();
        chooseAVideo.alpha = 0;
        chooseAVideo.x     = 20;
        chooseAVideo.y     = 336;
    }

    public function addNav():void
    {
        addChild(weAreA);
        addChild(introText);
        addChild(chooseAVideo);

        TweenLite.to(weAreA, 2, {alpha:1});
        TweenLite.to(introText, 3, {alpha:1});
        TweenLite.to(introText, 3, {alpha:1});
    }

1 个答案:

答案 0 :(得分:4)

看看这一行: intro.addEventListener("onComplete", nav.addNav);

触发事件时,将调用addNav并在参数中发送event个对象。