我对编程世界比较陌生,所以请耐心等待。我正在尝试制作一个程序教程,我应该在我的屏幕上让一个小家伙四处走动,但我不断收到有关不同事物的错误消息。我现在遇到的问题是错误代码 1046: Type was not found or is not compile-time constant: player
我尝试查找以前的错误,但没有发现与我自己相似的错误。我可能是一个肤浅的研究人员,但我宁愿直接问出什么问题并解决问题。
我正在使用 Flash CS6,代码如下:
package {
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
public class Main_Character extends MovieClip {
var vx: int;
var vy: int;
public
function Main_Character() {
init();
}
function init(): void {
vx = 0;
vy = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onKeyDown(event: KeyboardEvent): void {
if (event.keyCode == Keyboard.LEFT) {
vx = -5;
} else if (event.keyCode == Keyboard.RIGHT) {
vx = 5;
} else if (event.keyCode == Keyboard.UP) {
vy = -5;
} else if (event.keyCode == Keyboard.DOWN) {
vy = 5;
}
}
function onKeyUp(event: KeyboardEvent): void {
if (event.keyCode == Keyboard.LEFT)(event.keyCode == Keyboard.RIGHT) {
vx = 0;
}
if (event.keyCode == Keyboard.DOWN)(event.keyCode == Keyboard.UP) {
vy = 0;
}
}
function onEnterFrame(event: Event): void {
player.x += vx;
player.y += vy;
}
}
}
我之前尝试修复了几个点,但效果并不好。任何帮助都会很棒! - C