使用加载器显示对象加载 X 个 jpeg,然后在舞台上时以不同的方式调整每个图像的大小

发布于 2024-08-13 09:22:39 字数 943 浏览 9 评论 0原文

嘿,我想知道是否可以这样做,

我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2024-08-20 09:22:39

您可以创建多个加载器来加载多个文件:

public class Images extends Sprite
{
    private var imagesLoaded = 0;
    private var myArray:Array;

    ...

    public function Images():Void
    {
        myArray = [];

        for each (var url:String in myBunchOfURLS)
            loadURL(url);
    }

    private function loadURL(url:String):void
    {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        loader.load(new URLRequest(url));

        // you'll need to add the loader to the display list to see anything!
        addChild(loader);
    }

    private function imageLoaded(event:Event):void
    {
        var info:LoaderInfo = LoaderInfo(event.currentTarget);
        info.removeEventListener(Event.COMPLETE, imageLoaded);

        var loader:Loader = info.loader;
        myArray[imagesLoaded++] = loader;

        // or you could add the loader to the display list here instead?
    }
}

如果您必须有一个加载器,那么您需要等待每个加载完成,从加载的位图中获取位图数据,将其添加到新的位图中,然后开始加载下一张图像。这有点痛苦 - 如果我是你,我会坚持这种方法。

You could create multiple Loaders to load your multiple files:

public class Images extends Sprite
{
    private var imagesLoaded = 0;
    private var myArray:Array;

    ...

    public function Images():Void
    {
        myArray = [];

        for each (var url:String in myBunchOfURLS)
            loadURL(url);
    }

    private function loadURL(url:String):void
    {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        loader.load(new URLRequest(url));

        // you'll need to add the loader to the display list to see anything!
        addChild(loader);
    }

    private function imageLoaded(event:Event):void
    {
        var info:LoaderInfo = LoaderInfo(event.currentTarget);
        info.removeEventListener(Event.COMPLETE, imageLoaded);

        var loader:Loader = info.loader;
        myArray[imagesLoaded++] = loader;

        // or you could add the loader to the display list here instead?
    }
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文