Hi guys,
I’ve got an annoying little problem with recreating a RTS style interface, specifically with selection and issuing movement commands to units. It’s goes something like this…
public class Tank extends Sprite
{
public var isSelected:Boolean = false;
public function Tank()
{
selectBox_mc.visible = false;
addEventListener(MouseEvent.CLICK, handleClick);
}
public function handleClick(e:Event)
{
if (isSelected)
{
isSelected = false;
selectBox_mc.visible = false;
parent.removeEventListener(MouseEvent.CLICK, handleOrder);
}
else
{
isSelected = true;
selectBox_mc.visible = true;
parent.addEventListener(MouseEvent.CLICK, handleOrder);
}
}
}
The idea is that you click on the tank to select it (a new listener is added) and then you click again elsewhere on the screen to tell the tank to move/shoot whatever (the new listener is acted upon).
However what actually happens is that when you select the tank, the listener for “handleOrder” is added but is then also immediately executed…!? How, why, what the f…
Can anyone tell me what’s going on here?
Thanks