# addEventListener() with parameters - is my way right?

**URL:** https://forum.kirupa.com/t/addeventlistener-with-parameters-is-my-way-right/310162
**Category:** flash
**Created:** [June 3, 2010, 3:37am UTC](https://forum.kirupa.com/t/addeventlistener-with-parameters-is-my-way-right/310162 "2010-06-03T03:37:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sebby64](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sebby64](https://forum.kirupa.com/u/sebby64)
#### Post date: [June 3, 2010, 3:37am UTC](https://forum.kirupa.com/t/addeventlistener-with-parameters-is-my-way-right/310162/1 "2010-06-03T03:37:40Z")

</div>

I’ve been browsing lots of forums lately regarding the issues involved with passing parameters into functions called by event listeners. I think I may have come up with a good solution using anonymous functions but I’m not sure yet if its “safe” to do.

```auto
this.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
       myFunction(e, arguments.callee, "hello")
});

public function myFunction(e:Event, fct:Function, string:String) {
       e.currentTarget.removeEventListener(e.type,fct);
       trace(string);
}

```

The code prints “hello” once, which is what I wanted. I believe I have deleted the anonymous function, but I need some thoughts from those who may be more knowledgeable about flash garbage collection and such to be sure.
