Hey guys,
Couldnt find an answer to this one, so i hope someone can help me out here:
If the user click on a tower in my game, a small menu will open, i have to disable the mouse event listener for the tower then, other wise it’ll reposition it.
public function PlayerTower()
{
super(0x000000);
addChild(menuSprite);
menuSprite.visible = false;
this.addEventListener(MouseEvent.CLICK, menu);
}
public function menu(e:MouseEvent):void{
this.removeEventListener(MouseEvent.CLICK, menu);
menuSprite.visible = true;
menuSprite.x = this.mouseX;
menuSprite.y = this.mouseY;
}
public function removeMenu():void{
menuSprite.visible = false;
this.addEventListener(MouseEvent.CLICK, menu);
}
public function throwJunk(big:Boolean):void{
menuSprite.visible = false;
this.addEventListener(MouseEvent.CLICK, menu);
}
Here’s a part of the menu code:
public function cancelMenu(e:MouseEvent):void{
tower.removeMenu();
}
public function throwSmallJunk(e:MouseEvent):void{
tower.throwJunk(false);
}
public function throwBigJunk(e:MouseEvent):void{
tower.throwJunk(true);
}
Now the problem is that if i click something in the menu, the menu will still reposition itself, so if i for instance select cancel, it will set the menu’s visibilty to false, but then add the eventlistener and go straight to adding the menu back again.
Anyone can help me fix this?