I am currently develoing a flash game and I am trying to spawn 2 different symbols from a class. I have a Class called ‘PLayerClass’, which contains a variable called ‘hero’ which I assign a symbol to. This works fine with 1 symbol but I have no idea or if it is possible to assign a different symbol to the variable ‘hero’. The 2 symbols are ‘soldierOrange’ and ‘soldierGrey’. For both of these symbols I have matching classes (ie. soldierOrange.as).
Basicly, is there a way of assigning either symbol to the same variable ‘hero’ within PLayerClass? Any help would be really apreciated, thanks.
soldierOrange.as
package {
import flash.display.*;
public class soldierOrange extends Sprite {
public function soldierOrange(pos_X:int, pos_Y:int, pos_R:int):void{
x = pos_X;
y = pos_Y;
rotation = pos_R;
}
}
}
PlayerClass.as (I have cut out parts of the code)
public class PlayerClass extends MovieClip
{
public var hero:soldierOrange;
...
public function PlayerClass(...playerImage:String...):void{
...
this.playerImage = playerImage
...
if(playerImage == "soldierOrange"){
hero = new soldierOrange(30, 30, 90);
}
else{
hero = new soldierGrey(660, 660, 270);
}
}
public function spawnPlayer(pos_X:int, pos_Y:int, pos_R:int):void{
hero.x = pos_X;
hero.y = pos_Y;
hero.rotation = pos_R;
}
}