当我有此代码时,它会出现此错误“1061:通过静态类型 Class 的引用调用可能未定义的方法 hitTestPoint。”
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);
}
public function Code() {
// constructor code
}
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;
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;
}
}
}
}
}
我的选择是向我的平台添加一个 MovieClip 变量,这确实消除了这个错误,但我不确定如何将我的实际平台实例链接到我的变量。哦,顺便说一下平台的实例是平台。如果有人对如何解决此错误有任何线索,那就太好了。