# Deleting 'in function' listener with other function

**URL:** <https://forum.kirupa.com/t/deleting-in-function-listener-with-other-function/316652>\
**Category:** Uncategorized\
**Created:** [November 28, 2010, 10:06pm UTC](https://forum.kirupa.com/t/deleting-in-function-listener-with-other-function/316652 "2010-11-28T22:06:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![deshu1](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@deshu1](https://forum.kirupa.com/u/deshu1)\
**Post date:** [November 28, 2010, 10:06pm UTC](https://forum.kirupa.com/t/deleting-in-function-listener-with-other-function/316652/1 "2010-11-28T22:06:24Z")

</div>

Hello everybody.

I have a really annoying problem with removing eventListener created in public function, with another public function.

Is there a way to give a ‘name’ to a specific listener, to reference to it later on? Or maybe i can add listener to a array/dictionary?

Theres a code:

```auto

public function _c(target, posX:Number = 0, posY:Number = 0, autoUpdate:Boolean = true)
{		
	if(autoUpdate == true){
		thisStage.addEventListener(Event.RESIZE, exe);
           }
			
	else if(autoUpdate == false){
		thisStage.removeEventListener(Event.RESIZE, exe);
		trace("detach executed");
	}
			
	function exe()
           {
		target.x = (stageW - target.width)/2 + posX;
		target.y = (stageH - target.height)/2 + posY;
           }

			
	exe();
			
	// Assignments //
	target.attachment = _c;
	target.posX = posX;
	target.posY = posY;
}

///// DETACH /////
public function _detach(target)
{		
	target.attachment(target, target.posX, target.posY, false);
}

```

I am sure that ‘\_detach’ function is working properly, because i get ‘detach executed’ output.

**But, the listener added in 5th line doesn’t get removed, and i really don’t know why.**  
I am waiting for your help.

Thanks in advance
