Hi everybody, I’m a bit new to ActionScript 3.0 and I have a quick question. I’m writing a tower defense game, and the way I have the tower placement is on a grid, where each square has an Event Listener that checks if the user is currently placing a tower when clicked. When the user places a tower, it removes the Event Listener so they can’t place another tower on top of it.
My problem is, I want to re-add that Event Listener later in the game when the user sells a tower. The sell function is in a different tower class, so would it be possible to add the event listener to the block from the tower class?
Thanks in advance to anyone who has an idea
Here’s the click function in the Block Class
ActionScript Code:
[LEFT][COLOR=#0000FF]private[/COLOR] [COLOR=#000000]**function**[/COLOR] thisClick[COLOR=#000000]([/COLOR][COLOR=#0000FF]e[/COLOR]:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]money[/COLOR] >= [COLOR=#000080]20[/COLOR] && [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]placingTower[/COLOR] && [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]towerType[/COLOR] == [COLOR=#000080]1[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR][COLOR=#808080]//if the player has enough money and is placing a regular tower[/COLOR]
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]makeTurret[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]buttonMode[/COLOR] = [COLOR=#000000]false[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]graphics[/COLOR].[COLOR=#0000FF]beginFill[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]graphics[/COLOR].[COLOR=#000080]drawRect[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]graphics[/COLOR].[COLOR=#0000FF]endFill[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#808080]//Remove Button Listeners[/COLOR]
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]removeEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_OVER[/COLOR], thisMouseOver[COLOR=#000000])[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]removeEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]MOUSE_OUT[/COLOR], thisMouseOut[COLOR=#000000])[/COLOR];
[COLOR=#0000FF]this[/COLOR].[COLOR=#000080]removeEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]CLICK[/COLOR], thisClick[COLOR=#000000])[/COLOR];
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]money[/COLOR] -= [COLOR=#000080]20[/COLOR];
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]removeChild[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]rangeCircle[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]![COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]shiftDown[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]placingTower[/COLOR] = [COLOR=#000000]**false**[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]