开发者

Flash Error #1063: Argument count mismatch

开发者 https://www.devze.com 2023-02-18 22:12 出处:网络
ArgumentError: Error #1063: Argument count mismatch on scripts::GamePlay(). Expected 1, got 0. at flash.display::Sprite/constructChildren()
ArgumentError: Error #1063: Argument count mismatch on scripts::GamePlay(). Expected 1, got 0.
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at fl开发者_如何转开发ash.display::MovieClip()

I have some of these errors when I compile and I know the solution.

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

In the constructor I must add stageRef:Stage = null this will solve the error, but if I do that all my timers think the stage is null or something is null, like so.

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()

What can I do to fix this error?


When you call GamePlay, specify a Stage parameter.

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


Are you creating this object in the constructor of your main application's document class? If so, you'll run into this issue even if the rest of your code is perfect because of the way Flash Player works.

Basically, "Stage" is null until your main application is added to the stage. This is a quick shortcut to lots of unusual behavior and hard-to-trace bugs. A very common solution is to minimize the code in your document class's constructor. Instead of putting your init logic in your constructor, your constructor just adds an event listener for Event.ADDED_TO_STAGE, and your logic goes into your handler. It would look something like this:

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

Let me know if that solves your problem, it's possible I'm not entirely understanding what's going on - but regardless, if you're having issues where stage is null when it shouldn't be this is usually the cause.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号