# removeEventListener from a nested function

**URL:** <https://forum.kirupa.com/t/removeeventlistener-from-a-nested-function/306922>\
**Category:** flash\
**Created:** [March 24, 2010, 3:33pm UTC](https://forum.kirupa.com/t/removeeventlistener-from-a-nested-function/306922 "2010-03-24T15:33:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esseti](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@Esseti](https://forum.kirupa.com/u/Esseti)\
**Post date:** [March 24, 2010, 3:33pm UTC](https://forum.kirupa.com/t/removeeventlistener-from-a-nested-function/306922/1 "2010-03-24T15:33:00Z")

</div>

Example:

```auto

var btn:Sprite = new Sprite();
btn.graphics.beginFill(0x000);
btn.graphics.drawRect(-50, -50, 50, 50);
btn.graphics.endFill();
btn.x = stage.stageWidth/2;
btn.y = stage.stageHeight/2;

stage.addChild(btn);

function sampleFunction(_t:Object):void {
	trace("Still working! "+_t.target);
	//_t.target.removeEventListener(MouseEvent.MOUSE_DOWN, ???);
};

btn.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent){sampleFunction(e)}, false, 0, false);

```

Premise: I needed to pass a variable while defining the Listener for a object:  
btn.addEventListener(MouseEvent.MOUSE\_DOWN, function(e:MouseEvent){sampleFunction(e)}, false, 0, false);

Problem: Since I used a blank function(){} inside of the Listener, I don’t know how to later delete that function from that object (btn);

Is it possible? Or is there another way to pass variables while defining Listeners on objects?
