Passing variables in event listeners

Hey guys,

I’m aware that there has been a bunch of discussion on this already here and on other forums, but I just don’t see how the custom AS3 events can help me with this one. I’m probably missing something obvious.

I have a function that says this:


objectToSearchIn = myMovieClip;
pixelColour = 0xff0000;
position = myRectangle;
searchPixel(objectToSearchIn, pixelColour, position);

Then, in the searchPixel function:


public function searchPixel (myMovieClip:pixelRing, colour:uint, position:Point):void {
     myMovieClip.addEventListener(Event.ENTER_FRAME, myEnterFrameFunction);
}

My understanding is that in order to pass the variables that need to get to the function myEnterFrameFunction, I need to create a custom event handler. But in order to call this custom event handler onEnterFrame, I need to use a standard ENTER_FRAME to call my custom handler. Because the ENTER_FRAME cannot take variables, I lose my parameters during that step.

Have I missed something big here? Is there a simple but elegant way to get those variables into my enterframe function? I’d rather not start using class level variables if I can help it.

Thanks!

Rich.