我正在尝试让我们actionscript 3
尝试使用变量来播放单独的动画,但在flash cs6
中不起作用,并且我的学校也不会更新它。
我尝试在变量的上下文中使用它,但是它总是会显示错误消息:
var currentDirection = event.charCode;
Scene 1, Layer 'Sprite', Frame 1, Line 10 1120:Access of undefined property event
答案 0 :(得分:1)
也许有一个完整的示例会有所帮助,该示例显示了AS3中完成此操作所需的所有代码:
import flash.events.KeyboardEvent;
//var to hold the last key pressed.
var currentDirection:int = -1;
//listen for the key down event, when it happens, call the onKeyDown function below
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
//this function runs whenever a key goes down
function onKeyDown(event:KeyboardEvent) {
currentDirection = event.charCode; //assign the var the current key press char code
trace(event.charCode); //trace to the output panel to see if it's working
}