one easy way : 

function fn(i:uint)
{
var R1:ResultLink = new ResultLink(data[i].CompanyName,
data[i].CompanyId); //
    R1.addEventListener(MouseEvent.CLICK, function():void
{trace(R1.Label)});
    BlackBox.addChild(R1);
    //x and y here
   }
}

--- On Wed, 9/17/08, Omar Fouad <[EMAIL PROTECTED]> wrote:
From: Omar Fouad <[EMAIL PROTECTED]>
Subject: [Flashcoders] Adding Listeners in a loop
To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
Date: Wednesday, September 17, 2008, 5:47 PM

Hi,
I got this loop that creates some MovieClips one under another.
for (var i:uint = 0; i < data.length; i++) {
    var R1:ResultLink = new ResultLink(data[i].CompanyName,
data[i].CompanyId); //
    R1.addEventListener(MouseEvent.CLICK, function():void
{trace(R1.Label)});
    BlackBox.addChild(R1);
    //x and y here
   }
Where ResultLink is a Class that extends MovieClip and holds The Label, and
The Id property from a Dataset fetched from a SQLite database and returned
into the array 'data'.

Now when I click to each one of the created MovieClips, they trace the last
Label and not the corresponding label for each MovieClip Clicked. At this
point I think that the event listener is added to the same 'instace'
that is
overridden everytime.

How can I fix this?

Thanks


-- 
Omar M. Fouad - www.omar-fouad.net
Cellular: (+20) 1011.88.534
Mail: [EMAIL PROTECTED]

This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an
intended recipient then please promptly delete this e-mail and any
attachment and all copies and inform the sender. Thank you.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



      
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to