Actionscript 3 在Actionscript中使用数组加载多个图像
我有一个课堂作业,我必须创建一个照片库,其中一个规定是图像需要从外部来源加载。我们任务中的参考代码为:Actionscript 3 在Actionscript中使用数组加载多个图像,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,我有一个课堂作业,我必须创建一个照片库,其中一个规定是图像需要从外部来源加载。我们任务中的参考代码为: var myRequest:URLRequest = new URLRequest("bw1.jpg"); myLoader.load(myRequest); addChild(myLoader); 我的特殊需求要求我一次在屏幕上最多有两份图像,一份作为缩略图,另一份作为全尺寸图像。我希望这样,当用户单击缩略图时,会创建一个新的图片实例,并以0 alpha缩放到全尺寸,当前选定的图片的a
var myRequest:URLRequest = new URLRequest("bw1.jpg");
myLoader.load(myRequest);
addChild(myLoader);
我的特殊需求要求我一次在屏幕上最多有两份图像,一份作为缩略图,另一份作为全尺寸图像。我希望这样,当用户单击缩略图时,会创建一个新的图片实例,并以0 alpha缩放到全尺寸,当前选定的图片的alpha值会随着新图片的alpha值增加而减少。一旦旧照片不再可见,它将从舞台上移除
我很难弄清楚如何在actionscript中创建映像的副本,而且我的for循环似乎没有正确执行,因为即使没有错误消息,它也只经过一次迭代
这里有一个通过pastebin链接到我的代码的链接:但为了避免您在这两者之间来回切换,我也将在这里跳过它
import flash.display.Bitmap;
//creates a loader for each picture to be loaded, I know I could have an empty array
that I add to but created a full array to test.
var loaders:Array = [new Loader(),new Loader(), new Loader(), new Loader(), new
Loader(), new Loader(), new Loader(), new Loader(), new Loader(), new Loader()];
//stores the url request for each image to be loaded
var Requests:Array =[new URLRequest("pic1.jpg"),new URLRequest("pic2.jpg"),new
URLRequest("pic3.jpg"),
new URLRequest("pic4.jpg"),new URLRequest("pic5.jpg"),new URLRequest("pic6.jpg"), new
URLRequest("pic7.jpg"),
new URLRequest("pic8.jpg"), new URLRequest("pic9.jpg"),new URLRequest("pic10.jpg")];
//creates 2 empty arrays one to store the thumbnail sized pics the other fullsized.
Ideally I want one Array holding the bitmap data and the other holding the thumbnail
instances since I only need 2
// fullsized images at a time I can just create a new one and erase the old one in a
single function.
var pics:Array = new Array();
var pics2:Array = new Array();
//defines an empty bitMap variable as a placeholder for which to copy from redefined in
every iteration of the loop
var test:Bitmap;
//loops through every loader
for (var i in loaders);
{
// loads the loader and url request and creates a picture
loaders[i].load(Requests[i]);
//waits for the pic to load
loaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
//after loader is loaded create pic from the data
function loadComplete(evt:Event):void
{
var i = "Test";
trace(i);
test= evt.target.content as Bitmap;
pics2[i] = test;
pics[i] =new Bitmap(test.bitmapData);
pics2[i] =new Bitmap(test.bitmapData);
//creates an image on the stage at runtime to help debug
var pic1 = new Bitmap(test.bitmapData);
addChild(pics[i])
pic1.scaleX = 0.138427734375;
pic1.scaleY = 0.1384114583333333;
pic1.x = 204;
pic1.y = 20.6;
pic1.alpha = .25;
var pic2:Bitmap = new Bitmap(test.bitmapData);
pic2.x =100;
pic2.y =100;
pic2.scaleX =.33;
pic2.scaleY=.33;
addChild(pic2);
loaders[i].contentLoaderInfo.removeEventListener(Event.COMPLETE,
loadComplete)
}
}
for循环的设置方式是,它将尝试迭代装入器实例的每个属性,这不是您想要的。您可能还需要研究其他AS3批量加载程序选项,因为已经有一些脚本可以帮助您解决这个问题 你的循环应该是这样的
for(var i=0; i<loaders.length; i++)
{
var curLoader = loaders[i].load(Requests[i]);
(变量i=0;i)的