Hi. This is my first try to program a game in flash and Im having trouble making my character move. I want to work with class files for the player, to have all the code for the player in that class. So I put the movement code there and it moves, but I cant make it play its animations, like when moving, the player movie clip, should play the walking animation, but it doesnt. Pls help me.
Heres the code for the Engine class asociated to the stage and the Actor class asociated to the player:
ActionScript Code:
package
{
import flash.display.MovieClip;
public class Engine extends MovieClip
{
public function Engine():void
{
var player:Player = new Player(stage);
addChild(player);
}
}
}
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.ui.Keyboard;
public class Player extends MovieClip
{
private var stageRef:Stage;
var vel:int = 5;
private var _movingUp:Boolean = false;
private var _movingDown:Boolean = false;
private var _movingLeft:Boolean = false;
private var _movingRight:Boolean = false;
public function Player(stageRef:Stage):void
{
this.stageRef = stageRef;
stageRef.addEventListener(KeyboardEvent.KEY_UP,Release);
stageRef.addEventListener(KeyboardEvent.KEY_DOWN,Press);
addEventListener(Event.ENTER_FRAME,Loop);
x = stageRef.stageWidth / 2;
y = stageRef.stageHeight / 2;
trace("Inst");
trace(this.name);
gotoAndStop('still');
}
public function Loop(e:Event):void
{
// Move up, down, left, or right
if (_movingLeft && ! _movingRight)
{
this.gotoAndStop('walking');
this.x -= vel;
this.scaleX = 1;
}
else if (!_movingLeft && _movingRight)
{
this.gotoAndStop('walking');
this.x += vel;
this.scaleX = -1;
}
else
{
this.gotoAndStop('still');
}
}
public function Press(event:KeyboardEvent):void
{
switch ( event.keyCode )
{
case Keyboard.UP :
_movingUp = true;
break;
case Keyboard.DOWN :
_movingDown = true;
break;
case Keyboard.LEFT :
_movingLeft = true;
break;
case Keyboard.RIGHT :
_movingRight = true;
break;
}
}
public function Release(event:KeyboardEvent):void
{
switch ( event.keyCode )
{
case Keyboard.UP :
_movingUp = false;
break;
case Keyboard.DOWN :
_movingDown = false;
break;
case Keyboard.LEFT :
_movingLeft = false;
break;
case Keyboard.RIGHT :
_movingRight = false;
break;
}
}
}
}
Also u can dl the fla, for CS3. Need help plz.