views:

125

answers:

2

Hello

I am having trouble attaching eventListeners to the elements within my array, any help/suggestions would be great.. thanks for reading

   var urls:Array=["../showcaseThumbnails/1.jpg",
"../showcaseThumbnails/2.jpg",
"../showcaseThumbnails/3.jpg",
"../showcaseThumbnails/4.jpg",
"../showcaseThumbnails/5.jpg",
"../showcaseThumbnails/6.jpg"];
var loader:Loader;
for (var i:int=0;i<urls.length;i++)
{
   loader=startLoading(urls[i]);
   loader.y=510;
   loader.x=i*54+314;
   addChild(loader);
}

function startLoading(url:String):Loader
{
var loader:Loader=new Loader();
loader.load(new URLRequest(url));
return loader;
} 
A: 
var urls:Array=["../showcaseThumbnails/1.jpg",
"../showcaseThumbnails/2.jpg",
"../showcaseThumbnails/3.jpg",
"../showcaseThumbnails/4.jpg",
"../showcaseThumbnails/5.jpg",
"../showcaseThumbnails/6.jpg"];

var loaders:Array = [];//array to store loaders
var loader:Loader;
for (var i:int=0;i<urls.length;i++)
{
   loader=startLoading(urls[i]);
   loaders.push(loader);
   loader.y=510;
   loader.x=i*54+314;
   addChild(loader);
}

function startLoading(url:String):Loader
{
   var loader:Loader=new Loader();
   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
   loader.load(new URLRequest(url));
   return loader;
} 
function onLoad(e:Event):void
{
   var index:Number = loaders.indexOf(LoaderInfo(e.target).loader);
   trace(urls[index]);
   //call the corresponding function from here based on index.
}
Amarghosh
My bad, I should have been more specific, I want to target each "jpg" within my array with a specific eventlistener. Is it even possible when the array is made up of URLS?
steven
+2  A: 

I guess you don't need one more array. you can use loaderInfo's url property to find out the URL.

function onLoad(e:Event):void {
  var url:String = e.traget.url;
  var index:Number = urls.indexOf(url);
}

bhups
ya, u r right. +1
Amarghosh