0
我有这个代码与平台的变量,我试图链接与我的.fla文件的平台的实际对象,但我得到这个错误,当我运行它; ArgumentError:错误#1063:代码()上的参数计数不匹配。预期1,得到0.在我的输出窗口。我的代码得到一个参数错误,期待1但得到0 - AS3
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的文件名是代码,以及FLA文件名是游戏。我的目标是让我的玩家使用箭头键在平台上移动。我的平台的链接是“平台”。如果任何人都可以提供帮助,那就太好了
哦,好吧,你能帮助那个哈哈? –
只需创建平台对象并将其传递到您调用代码构造函数 – upog
的位置,或者如果不需要将其更改为默认值,如下所示:'Code(value:Platform = null)' - 当然如果您的类需要'平台'后面你需要有一个方法来设置它。 –