# Removing event listeners

**URL:** https://forum.kirupa.com/t/removing-event-listeners/325869
**Category:** Uncategorized
**Created:** [November 9, 2011, 11:21am UTC](https://forum.kirupa.com/t/removing-event-listeners/325869 "2011-11-09T11:21:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![theMonitor](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@theMonitor](https://forum.kirupa.com/u/theMonitor)
#### Post date: [November 9, 2011, 11:21am UTC](https://forum.kirupa.com/t/removing-event-listeners/325869/1 "2011-11-09T11:21:08Z")

</div>

My apologies in advance… it’s another ‘Removing event listeners’ thread.

I have the following code, adding monsters to the stage:

```auto

stage.addEventListener(Event.ENTER_FRAME, mainLoop);

function mainLoop(Event):void {

if(Math.random()*100 < 1) {
generateMonster();
}

}

// --

function generateMonster():void {

var newMonster:Monster = new Monster();

// [Set 'Monster' properties such as x and y values]

addChild(newMonster);
newMonster.addEventListener(Event.ENTER_FRAME, monsterLoop);

}

// --

function monsterLoop(Event):void {

// [Move monster around stage]

if(Event.target.hitTestObject(hero)) {

// Remove monster and listener:
var target:DisplayObject = Event.target as DisplayObject;
target.removeEventListener(Event.ENTER_FRAME, monsterLoop);
target.parent.removeChild(target);

}

}

```

However, as I’m sure those of you who know what’s going wrong have guessed, this results in the error message “ReferenceError: Error #1069: Property ENTER\_FRAME not found on flash.events.Event and there is no default value. at test\_fla::MainTimeline/monsterLoop()”

I am blanking on a solution to this at the moment - could anyone help?
