# Super and subclasses

**URL:** <https://forum.kirupa.com/t/super-and-subclasses/300277>\
**Category:** flash\
**Created:** [November 18, 2009, 5:42pm UTC](https://forum.kirupa.com/t/super-and-subclasses/300277 "2009-11-18T17:42:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neubema](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@Neubema](https://forum.kirupa.com/u/Neubema)\
**Post date:** [November 18, 2009, 5:42pm UTC](https://forum.kirupa.com/t/super-and-subclasses/300277/1 "2009-11-18T17:42:49Z")

</div>

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?

```php

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?
