Code :-
=====
import flash.events.Event;
graphics.lineStyle(2);
graphics.beginFill(0x00ff00);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
function onKeyPressed(evt:KeyboardEvent):void
{
switch (evt.keyCode)
{
case Keyboard.UP :
//box= box.y++;
box.y = box.y - 1;
graphics.moveTo(box.x, box.y);
graphics.lineTo(box.x, box.y-1);
trace("up");
break;
case Keyboard.DOWN :
///box= box.y--;
box.y = box.y + 1;
graphics.moveTo(box.x, box.y);
graphics.lineTo(box.x, box.y+1);
trace("down");
break;
case Keyboard.LEFT :
//box= box.x--;
box.x = box.x - 1;
graphics.moveTo(box.x, box.y);
graphics.lineTo(box.x-1, box.y);
trace("left");
break;
case Keyboard.RIGHT :
//box= box.x++;
box.x = box.x + 1;
graphics.moveTo(box.x, box.y);
graphics.lineTo(box.x+1, box.y);
trace("right");
break;
default :
trace("keyCode:", evt.keyCode);
}
}
out put :-
======
No comments:
Post a Comment