To move the MC, using arrow keys I used the following and it worked: var timer:Timer; var direct:String; initStage();
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;
}
}
I tried to convert this to use my onstage buttons: up_btn, down_btn, left_btn, right_btn to move MC box but couldn't figure it out. Can anyone help me convert this? Thanks in advance for any help you might offer. Annie