无法显示数组中的文件

发布于 2024-10-12 06:49:50 字数 660 浏览 0 评论 0原文

我正在尝试做一个图片库。最初我无法显示存储在数组中的缩略图。相反,它会继续显示相同的缩略图。解决这个问题后,我面临另一个问题..我不断收到错误 Error #2044: Unhandled ioError:。 text=错误 #2124:加载的文件类型未知。当我单击缩略图加载 .txt 文件时。

我可以命令预加载器跟踪下载进度吗?

 public function loadImage(filename:String):void
        {
            // show the preloader
            preloader.visible = true;

    // set the source to the UILoader to the full size image to load and display

            addChild(preloader);

            // command the preloader to track the progress of the download
            var loadWindow:UILoader;    
        preloader.trackLoading("LOADING: " + (loader*100).toFixed(0) + "%");


        }

i'm trying to do an image gallery. initially i was not able to display the thumbnails stored in the array. instead it keep showing the same thumbnails. with that solve i'm facing another problem.. i'm keep getting an error Error #2044: Unhandled ioError:. text=Error #2124: Loaded file is an unknown type. when i click on the thumbnail to load the .txt file.

hw can i command the pre-loader to track the progress of the download?

 public function loadImage(filename:String):void
        {
            // show the preloader
            preloader.visible = true;

    // set the source to the UILoader to the full size image to load and display

            addChild(preloader);

            // command the preloader to track the progress of the download
            var loadWindow:UILoader;    
        preloader.trackLoading("LOADING: " + (loader*100).toFixed(0) + "%");


        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

旧情勿念 2024-10-19 06:49:50

实际上这是很明显的。您不断地覆盖同一个变量。

拇指.textFile =“文本/图片1.txt”;

拇指.textFile =“文本/图片2.txt”; //第一个值丢失

thumbs.textFile = "text/picture3.txt"; //第二个值丢失

...等等

所以在这里您将继续添加最后一个图像,即循环的每次迭代中的第七个图像。

查看 weltraumpirat 的答案以获得正确的代码。


另外,您实际上并不需要排列名称为 Image_1、Image_2、Image_3... 的文件。

如果它们已经这样排列,那么您实际上可以不需要所有这些数组。我不知道这样做的效率或效果如何,但出于时间考虑,我老实说会采用如下所示的解决方案:

 for (var i:int = 0; i <7; i++) 
    {
        var thumbs:MyUIThumbnail = new MyUIThumbnail();    
        thumbs.y = 43 * i;    
        thumbs.image         = "images/image" +i +".jpg";
        thumbs.textFile      = "text/picture" +i +".txt";
        thumbs.imageFullSize =  full_image_mc;
        thumbs.infoText      =  info;
        thumbs.loadThumbnail("images/image"+i+"_thumb.jpg");    
        addChild(thumbs);
    }

It is quite obvious actually. You are continuously overwriting the same variable.

thumbs.textFile = "text/picture1.txt";

thumbs.textFile = "text/picture2.txt"; //1st value lost

thumbs.textFile = "text/picture3.txt"; //2nd value lost

...and so on

So here you will keep on adding the last one i.e the seventh image in every iteration of the loop.

look at weltraumpirat's answer for the right code.


Also you don't really need to arrange the files with names as Image_1, Image_2, Image_3....

If they were already arranged as such, you could have actually done aways without all those arrays. I don't know how efficient or better that would have been, but for time sake, I honestly would have jumped on to a solution something like the following:

 for (var i:int = 0; i <7; i++) 
    {
        var thumbs:MyUIThumbnail = new MyUIThumbnail();    
        thumbs.y = 43 * i;    
        thumbs.image         = "images/image" +i +".jpg";
        thumbs.textFile      = "text/picture" +i +".txt";
        thumbs.imageFullSize =  full_image_mc;
        thumbs.infoText      =  info;
        thumbs.loadThumbnail("images/image"+i+"_thumb.jpg");    
        addChild(thumbs);
    }
等数载,海棠开 2024-10-19 06:49:50

您没有正确访问数组。查看[] 运算符

for (var i:int = 0; i <7; i++) {
    var thumbs:MyUIThumbnail = new MyUIThumbnail();

    thumbs.y = 43 * i;

    thumbs.image = images[i];
    thumbs.textFile = textFiles[i];
    thumbs.imageFullSize = full_image_mc;
    thumbs.infoText = info;
    thumbs.loadThumbnail(thumbnails[i]);

    addChild(thumbs);
}

You are not accessing the arrays correctly. Have a look at the [] operator.

for (var i:int = 0; i <7; i++) {
    var thumbs:MyUIThumbnail = new MyUIThumbnail();

    thumbs.y = 43 * i;

    thumbs.image = images[i];
    thumbs.textFile = textFiles[i];
    thumbs.imageFullSize = full_image_mc;
    thumbs.infoText = info;
    thumbs.loadThumbnail(thumbnails[i]);

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