我的代码得到一个参数错误,期望1但得到0 - AS3

时间:2013-10-23 03:39:27

标签: actionscript-3 flash mismatch

我有一个平台变量的代码,我试图在我的.fla文件中链接Platform的实际对象,但是当我运行它时会出现这个错误; ArgumentError:错误#1063:Code()上的参数计数不匹配。预期1,得到0.在我的输出窗口中。

package  {

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.ui.Keyboard;


public class Code extends MovieClip {

    var charSpeed:int = 0;
    var velocity:int = 0;
    var gravity:Number = 1;
    var Jump:Boolean = false;


    public function startGame(){
         stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyDown);
         stage.addEventListener(KeyboardEvent.KEY_UP, checkKeyUp);
         stage.addEventListener(Event.ENTER_FRAME, loop);
     }

    private var platform:Platform;

    public function Code(value:Platform) {
        platform = value;
    }

    function checkKeyDown(evt:KeyboardEvent){
        if (evt.keyCode == Keyboard.LEFT){
            charSpeed -= 10;
        }
        if (evt.keyCode == Keyboard.RIGHT){
            charSpeed += 10;
        }
        if (evt.keyCode == Keyboard.DOWN){
            if(!Jump){
                velocity -= 14;
                Jump = true;
            }
        }
    }

    function checkKeyUp(evt:KeyboardEvent){
        if (evt.keyCode == Keyboard.LEFT){
            charSpeed = 0;
        }
        if (evt.keyCode == Keyboard.RIGHT){
            charSpeed = 0;
        }
    }

    function loop(evt:Event){
        player.x = velocity;
        if (player.x < 0){
             player.x = 0;
        }
        if (player.x > 550){
             player.x = 550;
        }

        velocity += gravity;

        var Platform:Array = new Array(platform)


        if (!Platform.hitTestPoint(player.x, player.y, true)){
            player.y += velocity;
        }

        for (var i = 0; i < 10; i++){
            if (Platform.hitTestPoint(player.x, player.y, true)){
                player.y--;
                velocity = 0;
                Jump = false;
            }
        }
    }
}

}

as3文件名是Code,fla文件名是Game。我的目标是让我的播放器使用箭头键在平台上移动。我的平台的链接是“平台”。如果有人能提供帮助,那就太棒了

1 个答案:

答案 0 :(得分:2)

Code(value:Platform)构造函数期望类型为Platform的参数,但似乎您正在调用代码而不通过'Platform'。在创建代码对象时需要传递“平台”参数