loader.close 出现问题

发布于 2024-11-17 03:53:15 字数 1055 浏览 3 评论 0原文

有人能解释一下为什么 loader.close 不起作用吗? 顺便说一句,我知道从服务器加载文件的事情。

for (var p:Number = 0; p < itemsOnPage; p++) 
{
    if (itterationStep != SqlRec.itemsArray.length) 
    {
        thumbImgLoader = new Loader();
        var imgName:String = SqlRec.itemsArray[itterationStep]["img"];
        thumbImgLoader.load(new URLRequest(GetXMLprefs.thumbsPath + imgName));
        thumbLoadersArray.push(thumbImgLoader);
        ...
    }
}

/////

if (ItemsBuilder.thumbLoadersArray) 
{
    if(ItemsBuilder.thumbLoadersArray.length > 0)
    {
        for (var i:Number = 0; i < ItemsBuilder.thumbLoadersArray.length; i++) 
        {
            try 
            {
                var obj:Loader = new Loader();
                obj = ItemsBuilder.thumbLoadersArray[i];
                obj.close();
                trace(">> "+obj.close);
            }catch (err:Error) 
            {
                trace(err)
            }
        }
        ItemsBuilder.thumbLoadersArray.splice(0, ItemsBuilder.thumbLoadersArray.length);
    }
}

Can anybody explain, why loader.close didn't work?
Btw i know about loading files from server thing.

for (var p:Number = 0; p < itemsOnPage; p++) 
{
    if (itterationStep != SqlRec.itemsArray.length) 
    {
        thumbImgLoader = new Loader();
        var imgName:String = SqlRec.itemsArray[itterationStep]["img"];
        thumbImgLoader.load(new URLRequest(GetXMLprefs.thumbsPath + imgName));
        thumbLoadersArray.push(thumbImgLoader);
        ...
    }
}

/////

if (ItemsBuilder.thumbLoadersArray) 
{
    if(ItemsBuilder.thumbLoadersArray.length > 0)
    {
        for (var i:Number = 0; i < ItemsBuilder.thumbLoadersArray.length; i++) 
        {
            try 
            {
                var obj:Loader = new Loader();
                obj = ItemsBuilder.thumbLoadersArray[i];
                obj.close();
                trace(">> "+obj.close);
            }catch (err:Error) 
            {
                trace(err)
            }
        }
        ItemsBuilder.thumbLoadersArray.splice(0, ItemsBuilder.thumbLoadersArray.length);
    }
}

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

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

发布评论

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

评论(1

要走就滚别墨迹 2024-11-24 03:53:15

你从痕迹中得到什么了吗?

Flash 对于一次可以同时执行的并发加载数量有一个内部限制。您正在循环加载 800 张图像,这意味着前 780 张左右的图像将被后 20 张左右的图像覆盖。我一次加载的最大数量约为 10 个(我认为 BulkLoader 有类似的东西) 。如果您想加载 800 张图像,请使用数组来跟踪加载的内容。类似于:

private var m_imagesLoaded:int = 0;
private var m_toLoad:Array = null;

private function _init():void
{
    // create your array and set the first 10 or so loading
    this.m_toLoad = new Array( 800 );
    ...
}

private function _onImageLoad( e:Event ):void
{
    // load the next one in the list
    this.m_imagesLoaded++;
    this.m_toLoad[this.m_imagesLoaded].load();

    // do whatever else
}

至于 close(),它“取消 Loader 当前正在进行的 load() 方法操作实例。”如果 Loader 中没有发生 load(),那么可能什么也不会发生。

PS:在您的 try 语句中,您每次都会创建一个新的 Loader,然后再将其分配给其他内容。只需将其更改为

var obj:Loader = ItemsBuilder.thumbLoadersArray[i];

Are you getting anything out of the trace?

Flash has an internal limit with how many simultaneous loads it can do at once. You're loading 800 images in a loop, which means that the first ~780 or so will be overridden by the last 20 or so. The max I ever load at once is around 10 (I think BulkLoader has something similar). If you want to load in 800 images, use the array to keep track of what's loading in. Something like:

private var m_imagesLoaded:int = 0;
private var m_toLoad:Array = null;

private function _init():void
{
    // create your array and set the first 10 or so loading
    this.m_toLoad = new Array( 800 );
    ...
}

private function _onImageLoad( e:Event ):void
{
    // load the next one in the list
    this.m_imagesLoaded++;
    this.m_toLoad[this.m_imagesLoaded].load();

    // do whatever else
}

As for close(), it "Cancels a load() method operation that is currently in progress for the Loader instance." If there's no load() going on in the Loader, then nothing's probably going to happen.

P.S.: in your try statement, you're creating a new Loader everytime, before assigning it to something else. Just change it to

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