Hi.
For my Asteroid Game I´m going to use different styles for my flying objects.
But the basic properties should be always the same.
A superclass is the solution.
The rocketclass is an empty superclass, the engine.
Rocket = SuperClass not linked to library
SkyRocket = SubClass extends Rocket and is linked to library
SpaceShip = Subclass extends Rocket and is linked to library
I push instances of both classes into the same array for the collision detection. To which class should I reference later the objects inside the array. I use the superclass and it works. Is it the correct way?
public var
Public var rocket:Rocket //superclass extends MC, but not linked to library
public var skyRocket:SkyRocket; //subclass linked to library
public var spaceShip:SpaceShip; //subclass linked to library
public var rocketArray:Array = new Array;
....
....
....
....
function createRocket()
switch(whatplayerwants)
{
case "skyRocket"
skyRocket = new SkyRocket();
addChild SkyRocket;
rocketArray.push (skyRocket);
break;
case "spaceShip"
spaceShip = new SpaceShip();
addChild spaceShip;
rocketArray.push (spaceShip);
break;
}
....
....
....
function testCollision () {
var i:int = rocketArray.length -1;
while (i > -1)
{
rocket = rocketArray(i); //rocket = instance of superclass rockets = Array of instances of the subclasses
Ok, up to this point, it works, but I don´t think it is a smart way.
I can´t acess properties which a defined only for the subclasses.
For example mc´s inside the object on the stage.
Should I use 2 different arrays?