我无法将eventListeners附加到我的数组中的元素,任何帮助/建议都会很棒..感谢阅读
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;
}
答案 0 :(得分:2)
我猜你不需要再多一个阵列了。您可以使用loaderInfo的url属性来查找URL。
function onLoad(e:Event):void {
var url:String = e.traget.url;
var index:Number = urls.indexOf(url);
}
答案 1 :(得分:0)
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.
}