# removeEventListener

**URL:** https://forum.kirupa.com/t/removeeventlistener/254421
**Category:** Uncategorized
**Created:** [March 11, 2008, 11:13pm UTC](https://forum.kirupa.com/t/removeeventlistener/254421 "2008-03-11T23:13:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ziul](https://avatars.discourse-cdn.com/v4/letter/z/3be4f8/32.png) [@Ziul](https://forum.kirupa.com/u/Ziul)
#### Post date: [March 11, 2008, 11:13pm UTC](https://forum.kirupa.com/t/removeeventlistener/254421/1 "2008-03-11T23:13:37Z")

</div>

I’m having trouble properly removing an eventListener that keeps looping.

Here’s my code:

```auto
var speed:Number = 1.1;

button.addEventListener(MouseEvent.CLICK, splitBox);

function splitBox(evt:MouseEvent):void {
    button.addEventListener(Event.ENTER_FRAME, ease);
    }
    
function ease(evt:Event):void {
    Box1_mc.x = 140 - (140 - Box1_mc.x) / speed; 
    Box2_mc.x = 400 - (400 - Box2_mc.x) / speed;
    
    [COLOR=Red]if ([COLOR=RoyalBlue]Box1_mc has reached its x-coordinate destination[/COLOR]) {    
        [COLOR=RoyalBlue]Box1_mc.x = it's final x-coordinate destination[/COLOR]
        [COLOR=RoyalBlue]button.removeEventListener(Event.ENTER_FRAME, ease);[/COLOR] 
//stop running the 'ease' function
        }[/COLOR]
    
    trace(Box1_mc.x); [COLOR=Red]//when I trace I get 
an infinate number loop of 140 eventually, the 
coordinate where it's supposed to stop[/COLOR]
        }

button.buttonMode = true;

```

This would basically end the loop, and rest Box1\_mc after easing into position. I would then apply the same concept to Box2\_mc. I’m still a beginner, a simple explanation and help would be great.
