0
要使用箭頭鍵移動MC,我使用了以下內容並使用它: var timer:Timer; var direct:String; initStage();想使用舞臺按鈕移動MovieClip,而不是使用箭頭鍵
function initStage() {
stage.addEventListener(KeyboardEvent.KEY_DOWN,startMove);
}
function startMove(e:KeyboardEvent):void {
switch (e.keyCode) {
case Keyboard.RIGHT:
direct = "right";
break;
case Keyboard.LEFT:
direct = "left";
break;
case Keyboard.DOWN:
direct = "down";
break;
case Keyboard.UP:
direct = "up";
}
timer = new Timer(10);
timer.addEventListener(TimerEvent.TIMER, moveBox);
timer.start();
stage.removeEventListener(KeyboardEvent.KEY_DOWN, startMove);
stage.addEventListener(KeyboardEvent.KEY_UP, stopMove);
}
function stopMove(e:KeyboardEvent):void {
timer.stop();
initStage();
}
function moveBox(e:TimerEvent):void {
switch (direct) {
case "right":
box.x += 1;
break;
case "left":
box.x -= 1;
break;
case "up":
box.y -= 1;
break;
case "down":
box.y += 1;
break;
}
}
我試圖將它轉換爲用我的舞臺上的按鈕:up_btn,down_btn,left_btn,right_btn移動MC框,但無法弄清楚。任何人都可以幫我轉換這個? 預先感謝您提供的任何幫助。 安妮
是的,這對我的作品。非常感謝你。 – Anne 2010-03-23 16:04:01