0

我有这个带有平台变量的代码,我试图在我的 .fla 文件中与平台的实际对象链接,但是当我运行它时出现这个错误;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。我的目标是让我的玩家使用箭头键在平台上移动。我平台的联动是“平台”。如果有人可以提供帮助,那就太好了

4

1 回答 1

2

Code(value:Platform)构造函数需要一个类型的参数,Platform但似乎您正在调用代码而没有传递“平台”。您需要在创建代码对象时传递“平台”参数

于 2013-10-23T03:50:23.310 回答