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)' - 當然如果您的類需要'平臺'後面你需要有一個方法來設置它。 –