var speed:Number = 6;
var key:Number;
stage.addEventListener(KeyboardEvent.KEY_DOWN, animate);
stage.addEventListener(KeyboardEvent.KEY_UP, stopAnimation);
function animate(event:KeyboardEvent):void
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, animate);
key = event.keyCode;
smiley_mc.addEventListener(Event.ENTER_FRAME, moveSmiley);
}
function stopAnimation(event:KeyboardEvent):void
{
if (key == event.keyCode)
{
smiley_mc.removeEventListener(Event.ENTER_FRAME, moveSmiley);
stage.addEventListener(KeyboardEvent.KEY_DOWN, animate);
}
}
function moveSmiley(event:Event):void
{
switch (key)
{
case 37:
smiley_mc.x -= speed;
break;
case 38:
smiley_mc.y -= speed;
break;
case 39:
smiley_mc.x += speed;
break;
case 40:
smiley_mc.y += speed;
break;
default:
break;
}
}
/*
var myNumber:Number = 80;
if (myNumber == 10)
{
trace("myNumber equals 10");
}
else if (myNumber == 8)
{
trace("myNumber equals 8");
}
else
{
trace("myNumber does not equal 10 OR 8");
}
*/
/*var myLetter:String = "b";
switch (myLetter)
{
case "a":
trace("a");
break;
case "b":
trace("b");
break;
case "c":
trace("c");
break;
default:
break;
}*/
2009. február 17., kedd
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése