使用加载器显示对象加载 X 个 jpeg,然后在舞台上时以不同的方式调整每个图像的大小
嘿,我想知道是否可以这样做,
我可以使用 addChild(myLoader); 加载图像并轻松显示它;其中 myLoader 位于 classWide 私有范围内。 问题是,每当我在该类中调用将加载程序添加到舞台中的函数时,它都会清除旧的加载程序并将新的加载程序放入其中,即使我添加了一点,将 myLoader.name 更改为与多少图像相关的内容它已经完成了。 这是一个严重的障碍,因为除了知道需要加载多少图像并编写代码 X 次之外,我无能为力。问题是 URL 是从 XML 文件中读取的。
我的主要愿望是拥有一个包含我的加载器的类范围私有数组,并且每次加载完成时我都会使用 myArray.push(myLoader) 分配它们。有一个问题是它可以编译但它们永远不会显示
它会像这样写一样工作
public class Images extends Sprite
{
private var imagesLoaded = 0;
private var myLoader:Loader;
...
public function Images():Void
{
myLoader = new Loader;
//loop calling a myLoader.load(imageURL) for a bunch of urls
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
public function imageLoaded
{
myArray[imagesLoaded] = myLoader;
trace("does\'nt get to here!!");
addChild(myArray[imagesLoaded]);
imagesLoaded++;
}
}
Hey there, I was wondering if this is possible to do
I am able to load the image in and have it displayed easily enough by using addChild(myLoader); where myLoader is in the classWide private scope.
The problem is, whenever I call my function inside that class which adds the loader to the stage, it clears the old one and puts this new one in even if I add a bit where I change myLoader.name to something related to how many images it has completed.
This is a serious hinderance as I can't do anything besides KNOW how many images I will need to load and write the code X times. The problem being is that the urls are read from an XML file.
My main desire was to have a classWide private Array which contained my loaders and I would assign them using myArray.push(myLoader) each time the load had completed. There is a problem which is that it compiles but they never get displayed
it would work as this is written
public class Images extends Sprite
{
private var imagesLoaded = 0;
private var myLoader:Loader;
...
public function Images():Void
{
myLoader = new Loader;
//loop calling a myLoader.load(imageURL) for a bunch of urls
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
public function imageLoaded
{
myArray[imagesLoaded] = myLoader;
trace("does\'nt get to here!!");
addChild(myArray[imagesLoaded]);
imagesLoaded++;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建多个加载器来加载多个文件:
如果您必须有一个加载器,那么您需要等待每个加载完成,从加载的位图中获取位图数据,将其添加到新的位图中,然后开始加载下一张图像。这有点痛苦 - 如果我是你,我会坚持这种方法。
You could create multiple Loaders to load your multiple files:
If you have to have one loader, then you'll need to wait for each load to complete, get the bitmap data out of the loaded bitmap, add it to a new bitmap, then start loading the next image. That's a bit more of a pain - I'd stick to this approach if I were you.