# Add Event Listener from External Class

**URL:** <https://forum.kirupa.com/t/add-event-listener-from-external-class/304158>\
**Category:** flash\
**Created:** [February 2, 2010, 3:19pm UTC](https://forum.kirupa.com/t/add-event-listener-from-external-class/304158 "2010-02-02T15:19:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![goalieguy6](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@goalieguy6](https://forum.kirupa.com/u/goalieguy6)\
**Post date:** [February 2, 2010, 3:19pm UTC](https://forum.kirupa.com/t/add-event-listener-from-external-class/304158/1 "2010-02-02T15:19:46Z")

</div>

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]
