package {
// --------------------------------------------------------------------------------------
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
// Game class (MovieClip extension)
// --------------------------------------------------------------------------------------
public class Game extends MovieClip {
// game properties
var hero:MovieClip;
var keyLeftPressed:Boolean = false;
var keyRightPressed:Boolean = false;
var keyUpPressed:Boolean = false;
var keyAPressed:Boolean = false;
var keySPressed:Boolean = false;
public function Game():void
{
addEventListener(Event.ENTER_FRAME, enterFrameHandler, false, 0, true);
addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
}
private function init():void
{
hero = new MovieClip;
hero.onGround;
hero.gotoAndStop('idle');
}
private function enterFrameHandler():void
{
if (keyLeftPressed)
{
hero.gotoAndStop('walking');
hero.x =+5;
}
if (keyRightPressed)
{
hero.gotoAndStop('walking');
hero.x =-5;
}
}
private function keyDownHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.LEFT:
keyLeftPressed = true;
break;
case Keyboard.RIGHT:
keyRightPressed = true;
break;
}
}
private function keyUpHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.LEFT:
keyLeftPressed = false;
break;
case Keyboard.RIGHT:
keyRightPressed = false;
break;
}
}
}
}
it has no error but i cant move my character, it must stop at ‘idle’
i tried to put hero.gotoAndStop(‘idle’); but i guess that it doesnt read the keyframes of hero. what should i do ?? tnx in advance !