package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
* @author nombre de autor
*/
public class firstGame extends MovieClip
{
private var leftKeyIsDown:Boolean;
private var rightKeyIsDown:Boolean;
public var mcPlayer:MovieClip;
//setup game loop event listener
stage.addEventListener(Event.ENTER_FRAME, private function gameLoop():void
{
// if left key is currently down
if (leftKeyIsDown == true)
{
//move player left
mcPlayer.x -= 5;
}
// if right key is currently down
if (rightKeyIsDown)
{
//move player right
mcPlayer.x += 5;
}
}
public function firstGame()
{
//set up listeners for when keys are pressed and released
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
}
private function keyUp(e:KeyboardEvent):void
{
trace(e.keyCode)
if (e.keyCode == 37)//if right key is released
{
//right key is released
leftKeyIsDown = false;
}
if (e.keyCode == 39)
{
rightKeyIsDown = false;
}
}
private function keyDown(e:KeyboardEvent ): void
{
if (e.keyCode == 37)//if right key is pressed
{
//right key is released
leftKeyIsDown = true;
}
if (e.keyCode == 39)
{
rightKeyIsDown = true;
}
}
}
}
}
Arriba esta el movimiento de movieclip que se llama mcPlayer solo falta llamar al mcPlayer al stage algo que imagino es simple pero sigo sin lograr.