Code:
package {
import flash.display.*;
public class Game extends MovieClip {
// note - changed background to Background
private var bg:Background;
private var pp:PlayerPic;
private var ep:EnemyPic;
public function Game() {
trace("Game Constructer");
var bg = new Background();
addChild(bg);
pp = new PlayerPic();
pp.x = 125;
pp.y = 550;
pp.width = 50;
pp.height = 40;
addChild(pp);
ep = new EnemyPic();
ep.x = 55;
ep.y = 50;
ep.height = 40;
ep.width = 50;
addChild(ep);
}
}
}
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;
public class PlayerPic extends MovieClip {
public function PlayerPic() {
addEventListener(Event.ADDED_TO_STAGE, init);
trace("PlayerPic Constructer");
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(KeyboardEvent.KEY_DOWN, arrowMove);
}
private function arrowMove(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.LEFT) {
x -= 5;
if (x < 0) {
x = 0;
}
}
if (e.keyCode == Keyboard.RIGHT) {
x += 5;
if (x > 250) {
x = 250;
}
}
if (e.keyCode == Keyboard.UP) {
y -= 5;
if (y < 0) {
y = 0;
}
}
if (e.keyCode == Keyboard.DOWN) {
y += 5;
if (y > 550) {
y = 550;
}
}
}
}
}
Code:
package {
import flash.display.*;
import flash.events.*;
public class EnemyPic extends MovieClip {
public function EnemyPic() {
trace("EnemyPic Constructer");
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(Event.ENTER_FRAME, eFrame, false,0, true);
}
public function eFrame(e:Event):void {
if (x > this.stage.stageWidth + 80) {
x = -80;
}
}
}
}
HTH