Flash错误#1063:参数计数不匹配

时间:2011-03-21 15:09:48

标签: flash actionscript-3 flash-cs5

ArgumentError: Error #1063: Argument count mismatch on scripts::GamePlay(). Expected 1, got 0.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()

编译时我遇到了一些错误,我知道解决方案。

public function GamePlay(stageRef:Stage)
        {
            this.stageRef = stageRef;
            player = new Player(stageRef);

            waitTimer.addEventListener(TimerEvent.TIMER_COMPLETE, WaitTimer, false, 0, true);
            waitTimer.start();

            player.addEventListener(Event.REMOVED_FROM_STAGE, PlayerRemoved, false, 0, true);
        }

在构造函数中我必须添加stageRef:Stage = null这将解决错误,但是如果我这样做,我的所有计时器都认为阶段为null或者某些东西是null,就像这样。

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at scripts::GamePlay/WaitTimer()[C:\Users\Noodles\Documents\Flash Projects\BlockDrop\scripts\GamePlay.as:71]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.utils::Timer/tick()

我该怎么做才能解决此错误?

2 个答案:

答案 0 :(得分:2)

调用GamePlay时,请指定Stage参数。

function fn() //calling function
{
 GamePlay(Stage); //pass Stage to the GamePlay function.
}

答案 1 :(得分:1)

您是在主应用程序的文档类的构造函数中创建此对象吗?如果是这样,即使代码的其余部分因Flash Player的工作方式而完美,您也会遇到此问题。

基本上,在您的主应用程序添加到舞台之前,“Stage”为空。这是许多异常行为和难以追踪的错误的快捷方式。一个非常常见的解决方案是最小化文档类构造函数中的代码。您的构造函数只是为Event.ADDED_TO_STAGE添加一个事件监听器,而不是将init逻辑放在构造函数中,而您的逻辑将进入您的处理程序。它看起来像这样:

protected var gamePlay:GamePlay;

public function MyConstructor():void {
     this.addEventListener(Event.ADDED_TO_STAGE, addedHandler, false, 0, true);
}

protected function addedHandler(e:Event):void {
     this.removeEventListener(Event.ADDED_TO_STAGE, addedHandler);
     gamePlay = new GamePlay(this.stage);
}

让我知道如果这解决了你的问题,我可能不完全理解发生了什么 - 但无论如何,如果你遇到的问题是阶段是空的,那么它不应该是这通常是原因。 / p>