# How to Remove these Event Listeners

**URL:** <https://forum.kirupa.com/t/how-to-remove-these-event-listeners/280901>\
**Category:** flash\
**Created:** [February 2, 2009, 10:02pm UTC](https://forum.kirupa.com/t/how-to-remove-these-event-listeners/280901 "2009-02-02T22:02:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [February 2, 2009, 10:02pm UTC](https://forum.kirupa.com/t/how-to-remove-these-event-listeners/280901/1 "2009-02-02T22:02:52Z")

</div>

I’ve placed listeners on the var “topic\_mc” (below), but I’m not sure how to remove them properly:

```auto

        private function layoutTopics(modNum:Number, attachTo:MovieClip):void {
            topicLength = MainMenu.modArr[modNum].topicArr.length;
            if (Interface._ui != null) {
                pageLength = Interface._ui.pageArr.length;
            }
            for (var t:Number = 0; t<topicLength; t++) {
                if (modNum == 0 && t == 0) {
                    //Splash page should not be on the Menu screen
                } else {
                    topic_mc = new Topic();
                    attachTo.addChild(topic_mc);
                    topic_mc.name = "topic"+t;
                    topic_mc.title.text = MainMenu.modArr[modNum].topicArr[t].header;
                    //Special placement for module 0
                    if (modNum == 0) {
                        topic_mc.y = (topic_mc.height-1)*t+17;
                    } else {
                        topic_mc.y = (topic_mc.height-1)*t+75;
                    }
                    topic_mc.x = 12;
                    var topNum:Number = t+1;
                    topic_mc.id = getPageArrIndex(modNum, topNum);
                    topic_mc.moduleNumber = modNum;
                    topic_mc.topicNumber = topNum;
                    topic_mc.buttonMode = true;
                    topic_mc.useHandCursor = true;
                    topic_mc.mouseChildren = false;
                    topic_mc.addEventListener(MouseEvent.CLICK,loadTopic);

                    // ADDING A DELAY TO ALLOW TIME FOR THE "topic_mc" TO INSTANTIATE
                    topic_mc.addEventListener(Event.ENTER_FRAME, addDelay);
                    //trace(topic_mc.name);
                }
                function addDelay(evt:Event):void {

                    evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);
                    //trace(evt.target.name);

                    
                    //if available 
                    if (previousTopicState == "complete") {
                        evt.target.gotoAndStop("available");
                        previousTopicState = "incomplete";
                    }
                    //if visited/completed  
                    if (checkTopicComplete(modNum, topNum)) {
                        evt.target.gotoAndStop("completed");
                        previousTopicState = "complete";
                    } else {
                        //if in progress/incomplete topic 
                        if (Interface._ui != null) {
                            if (evt.target.moduleNumber == Interface._ui.currentModule) {
                                if (evt.target.topicNumber == Interface._ui.currentTopic) {
                                    evt.target.gotoAndStop("inProgress");
                                }
                            }
                        }
                    }
                }
            }
        }

```

Using

```auto
evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);

```

doesn’t really work - any trace statement I place within the event function will run for infinity. How do I call the objects properly to remove the listeners? Note: I’ve tried referring to currentTarget instead of target but that doesn’t make any difference.
