Passing parameters to event in a for loop

Hey all

I’m stuck at a problem when creating children in a for loop, then passing the i:int to a MouseEvent.CLICK event to each child. They all get the last i:int used in the loop.

So I made a custom event but passing that event the i:int doesn’t work either. I still get all the CLICKs to return the last “i” used. How do I fix this?

For loop:

for (var i:int=0; i < pics; i++) { // 10 pics for example
    plane = new Plane(cMaterials*,650,500,3,3);
    scene.addChild(plane);
                
    plane.container.addEventListener(MouseEvent.CLICK, onClick);
    function onClick(e:MouseEvent){
        trace(i) // all clicks return 9
        dispatchEvent( new CustomEvent(i, CustomEvent.CLICKED) ); // Tracing i from CustomEvent.CLICKED returns 9
    }
}

I’m guessing I have to make the first event on the container to be a custom one, but I don’t get how to make a custom event act as a click for example.

At the moment this is my custom event

package{
    import flash.events.*;

    public class CustomEvent extends Event {

        public static const CLICKED:String = "onClick";
        public var myProp:Object;

        public function CustomEvent(_myProp:Object=null, type:String=null, bubbles:Boolean=false, cancelable:Boolean=false) {
            super(type, bubbles, cancelable);
            myProp = _myProp;
            trace(myProp);
        }
        public override function clone ():Event
        {
            return new CustomEvent(myProp,type,bubbles,cancelable);
        }
    }
}

Any help appreciated!

Thanks

Edit: This same thread got a very nice answer so thought I’d link there if you need help with this aswell! : http://www.actionscript.org/forums/showthread.php3?p=666096#post666096