title: Passing parameters to event listeners / handlers
body: <p>How do you pass parameters / variables through event listeners? I've overcome this problem fairly effectively using anonymous functions; which is an incredibly simple solution, but at the end of the day, it smells like a giant loophole for functionality that I feel <em>should</em> be provided natively anyways.</p>
  
  <p>Normally life would go on, but as fate would have it, now I actually need to remove the listener, and doing so when you've using an anonymous function is a bit funky. So, once again, I'm trying to figure out how to pass parameters through to event listeners so that the event listeners can be removed by simply referencing the function.</p>
  
  <p>As odd as it may seem, I've overcome this issue <em>as well</em>, BUT, I don't like it and tired of using it. In my opinion it is code smell. But it works like a charm. I store the variable, object or whatever on the dispatching MovieClip. So, if I'm looping though an array of data, generating thumbnails on the fly, I simply store the data variable (normally an object with multiple properties) in the actual thumbnail MovieClip. Then I can access all the data in an event listener method by referencing:
  <pre>event.target.data</pre>.
  In this example, "data" is the name of the variable holding holding the information I want. Because another issue that crops up when I don't use this is, is that when I'm looping through an array and generating thumbnails that click to view large images, the index is not consistent. At the end of the loop, ALL the thumbails will all open an image using the last index of "i". So if I had an array with a length of 12, they'd all load the 12th image regardless of what thumbnail you clicked on. Storing the data into the MovieClip itself, creates a solid reference that never changes.</p>
  
  <p>This has been bothering me for some time now. Basically what I want to know is, <strong>is this good practice, are there better solutions out there?</strong>
  <br /><br />
  Below are some diet examples. I can post more detailed examples if necessary. All examples depict a thumbnail that loads a large image when clicked.</p>
  
  <p><br /><br /><br>
  <strong>Without the use of an anonymous function (the problem):</strong>
  <br /><br /></p>
  
  <pre>
  tempThumb.addEventListener(MouseEvent.CLICK, loadImage);
  
  public function loadImage(_event:MouseEvent):void  
  {
      // I don't have the variable _url and preparing a hot bath with a cold blade  
  }
  </pre>
  
  <p><strong>Use of an anonymous function:</strong></p>
  
  <pre>
  tempThumb.addEventListener(MouseEvent.CLICK, function(_event:MouseEvent) { loadImage("large.jpg"); } );
  
  public function loadImage(_url:String):void  
  {
      // I got the variable _url and packing away the razor blades  
  }
  </pre>
  
  <p><strong>Without the use of an anonymous function, but using my smelly Leprechaun technique of storing the data into the MovieClip dispatching the event</strong></p>
  
  <pre>
  tempThumb.data = "large.jpg";
  
  tempThumb.addEventListener(MouseEvent.CLICK, loadImage);
  
  public function loadImage(_event:MouseEvent):void  
  {
      trace(event.target.data);
      // I can access the variable  
  }
  </pre>
  
  <p>I'm not clued up on programming terminology, so I've dubbed the above the Leprechaun Technique. Storing / hiding variables in objects for later use / access. It solves all my problems and works amazingly well. But, if there is a better way to do it, I want to know <em>that</em> way.</p>