# Assigning either symbol to a variable within a class

**URL:** <https://forum.kirupa.com/t/assigning-either-symbol-to-a-variable-within-a-class/284857>\
**Category:** Uncategorized\
**Created:** [March 24, 2009, 12:51pm UTC](https://forum.kirupa.com/t/assigning-either-symbol-to-a-variable-within-a-class/284857 "2009-03-24T12:51:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ersk](https://avatars.discourse-cdn.com/v4/letter/e/a9a28c/32.png) [@Ersk](https://forum.kirupa.com/u/Ersk)\
**Post date:** [March 24, 2009, 12:51pm UTC](https://forum.kirupa.com/t/assigning-either-symbol-to-a-variable-within-a-class/284857/1 "2009-03-24T12:51:46Z")

</div>

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

```auto
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)

```auto
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;
	}
}

```
