【发布时间】:2019-11-23 16:12:57
【问题描述】:
我正在尝试在 Event.Complete 上传递一个参数,因此一旦它们加载图像,我就可以相应地处理它们的位置、存储它们等。见下面的代码和输出:
var pic:Array = ["https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"];
for (var ii: uint = 0; ii < pic.length; ii++) {
var imageURLRequest:URLRequest = new URLRequest(pic[ii]);
var myImageLoader:Loader = new Loader();
myImageLoader.load(imageURLRequest);
trace ("the ii: " + ii);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(evt:Event)
{
doIt(evt, ii)
} , false, 0, true);
function doIt(evt:Event, msg:int) {
//var myBitmapData:BitmapData = new BitmapData(myImageLoader.width, myImageLoader.height);
//myBitmapData.draw(myImageLoader);
//var myBitmap:Bitmap = new Bitmap;
//myBitmap.bitmapData = myBitmapData;
trace ("message : " + msg);
}
}
/////Output
the ii: 0
the ii: 1
the ii: 2
the ii: 3
message : 4
message : 4
message : 4
message : 4
///Expected Output
/////Output
the ii: 0
the ii: 1
the ii: 2
the ii: 3
message : 0
message : 1
message : 2
message : 3
感谢您的帮助 斯皮戈
【问题讨论】:
-
问题是,循环在任何实际加载发生之前完成,因此在任何这些 COMPLETE 事件发生时 ii 为 4。因此,输出。为了区分这些加载过程,您需要用一个类包装它们(或扩展 Loader 类),以便您可以设置自定义字段。
-
感谢您的回答,我一直在研究扩展器或包装器,但我无法使其工作:( ....这是我得到的最接近的一个,但我不断收到错误不匹配参数:stackoverflow.com/questions/39532177/…
标签: actionscript-3 flash