A series of tutorials showing how to program a game in ActionScript 3 using Adobe Flash. The game is a 2D space shooter, but it's going to be incredibly cool.
//THE SHIP CLASSpackage ships{ import flash.display.*; import flash.events.*; public class Ship extends Sprite { private var _shipImage:MovieClip; public function Ship() { //add event listener to stage stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); _shipImage = new blueLightFighterImage(); addChild(_shipImage); x = 275; y = 200; } //function to be called whenever event listener detects user input public function keyDownHandler(event:Event) { trace("I have pressed a key!"); } }}
TypeError: Error #1009: Cannot access a property or method of a null object reference. at ships::Ship$iinit() at spaceGame$iinit()
//THE DOCUMENT CLASSpackage{ import flash.display.*; import ships.Ship; import flash.events.*; public class spaceGame extends MovieClip { public function spaceGame() { //create new ship var myShip:Ship = new Ship(); //add event listener to stage which calls function within myShip stage.addEventListener(KeyboardEvent.KEY_DOWN, myShip.keyDownHandler); //add ship to display list addChild(myShip); } }}
allShips[i] = new Ship(); addChild(allShips[i]); allShips[i].addEventListeners();
//PILOT CLASS - sets commands for ship under pilot controlpackage pilots{ import ships.*; public class Pilot { //pilot can never modify attribute of Ship, only pass commands //The available commands: protected var _commandRotation:Number = 0.0; protected var _commandThrust:Boolean = false; //The ship being controlled protected var _ship:Ship; public function get commandRotation():Number { return _commandRotation; } public function get commandThrust():Boolean { return _commandThrust; } public function set ship(ship:Ship):void { _ship = ship; } public function Pilot() { } }}
No comments:
Post a Comment