# Problems removing an event listener

**URL:** <https://forum.kirupa.com/t/problems-removing-an-event-listener/318784>\
**Category:** flash\
**Created:** [January 30, 2011, 12:36pm UTC](https://forum.kirupa.com/t/problems-removing-an-event-listener/318784 "2011-01-30T12:36:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimjiminyjimjim](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jimjiminyjimjim](https://forum.kirupa.com/u/jimjiminyjimjim)\
**Post date:** [January 30, 2011, 12:36pm UTC](https://forum.kirupa.com/t/problems-removing-an-event-listener/318784/1 "2011-01-30T12:36:37Z")

</div>

I have an on enter frame listener defined in a function:

```auto

function sideClicked(e:MouseEvent):void {
	
	removeEventListener(Event.ENTER_FRAME, loop);
	var targetName=e.target.name;
	var a:Array=[];	
	a=targetName.split("_");			
	turnto = cube1["turn"+a[1]]();
	addEventListener(Event.ENTER_FRAME, looptoposition);
	
}

```

The looptoposition() function simple calls a function from a custom class repetitively to move an object until it reaches its position. This is the function it calls from the included custom class:

```auto

public function rotateToPos(a:Number,b:Number,c:Number):void {
		
		if(!cubeReady){return;}
					
		if(cube.rotationY<b){
			cube.rotationY+=3;
		}
		else if(cube.rotationY>b){
			cube.rotationY-=3;
		}

		sortFaces();
		updateShadow();
		
	}

```

This gets the desired result visually - the cube rotates until the chosen point and then stops - however the listener continues. I have two problems:

1. I would like to remove the listener but can’t seem to do so from the imported class - I’m having trouble referencing my functions in the root flash file.

2. I also need to declare that the function has completed - but the equalities mean that b is either greater or less than but never equal to? Whats a better way of getting the cube to rotate to a set position on each frame? The reason for the equalities are the cube can turn two different directions. So rotation could be negative.
