Code Example:
var gospels : Array = ["john", "mark", "matthew", "paul"];
for each (var book : String in gospels)
{
var loader : URLLoader = new URLLoader();
loader.load(new URLRequest("http://example.com/" + name));
trace(book) // outputs current value of array
loader.addEventListener(Event.COMPLETE, function(e : Event) : void {
trace(book); // prints paul 4 times
});
}
How can I get the event listener to use the value of the array in the loop when the event listener's function was called? I.e. when I call trace inside the event listener's function, how can I get it to output "john"
, "mark"
, "matthew"
, and "paul"
?