如何从闪存TileList的dataProvider中变化时,处理未处理#2044的错误?闪存、错误、未处理、dataProvider

2023-09-08 14:02:33 作者:来者不善.

我使用自定义的ImageCell根据项目渲染一个TileList组件。我知道,在某些时候它试图获取图像不会被发现,我能够通过对自定义的ImageCell装载机的IEOrror监听器来处理这个问题。

I have a tilelist component using a custom ImageCell based item renderer. I know that at times some of the images it is trying to retrieve will not be found and I am able to handle this via an IEOrror listener on the custom ImageCell loader.

不过,如果我设置数据提供者,则所有图像都完成了装载或错误处理一改之前,Flash调试播放器抛出了在Firefox未处理#2044错误,指出图像也不会被发现。在戏曲与调试播放器,它抛出一个#2044,说明负载从未完成。

However, if I set the data provider, then it is changed before all images have completed their loading or error process, the flash debug player throws up an unhandled #2044 error in firefox stating that an image could not be found. In opera with the debug player it throws a #2044 stating that a load never completed.

我无法找到一个方法来捕获并忽略这些错误,使他们不扔调试器播放器的对话了。此外,使用Flash Builder的IDE调试的时候,调试器不会对这些错误打破所有 - 这是只有在球员,而我能够打破其他错误,没有问题

I can't find a way to trap and ignore these errors so they don't throw the debugger player dialogue up. Also, when using the Flash Builder IDE to debug, the debugger doesn't break on these errors at all - it's only in the player while I'm able to break on other errors without problem.

这是因为,如果错误监听被设置在数据提供器发生变化时,但加载器仍在继续,抛出一个未处理#2044。

It is as if the error listener is being disposed of when the dataprovider changes, but the loader continues and throws an unhandled #2044.

如何处理effectivel任何想法?预先感谢您的时间和帮助 -

Any ideas on how to handle effectivel? Thanks in advance for your time and assistance -

B

推荐答案

在您的自定义单元格渲染器的构造函数,你需要一个事件侦听器添加到受保护的加载实例,并处理IO错误。

In the constructor of your Custom Cell Renderer, you need to add an event listener to the protected loader instance and handle the IOError.

下面是一个例子:

package
{
    import fl.controls.listClasses.ICellRenderer;
    import fl.controls.listClasses.ImageCell;
    import fl.controls.TileList;
    import fl.data.DataProvider;
    import fl.managers.StyleManager;
    import flash.events.EventDispatcher;
    import flash.events.*;
    import fl.containers.UILoader;

    public class CustomImageCell extends ImageCell implements ICellRenderer
    {  

        public function CustomImageCell() 
        {
            super();

            //do other stuff here

            loader.scaleContent = false;
            loader.addEventListener(IOErrorEvent.IO_ERROR, handleErrorEvent, false, 0, true);

            useHandCursor = true;
        }

        override protected function drawLayout():void
        {
            var imagePadding:Number = getStyleValue("imagePadding") as Number;
            loader.move(11, 5);

            var w:Number = width-(imagePadding*2);
            var h:Number = height-imagePadding*2;
            if (loader.width != w && loader.height != h)
            {
                loader.setSize(w,h);
            }
            loader.drawNow(); // Force validation!

        }
        override protected function handleErrorEvent(event:IOErrorEvent):void {
            trace('ioError: ' + event);
            //dispatchEvent(event);
        }
    }
}

下面是一个简单的测试,我没有看到,当数据提供商得到更新会发生什么:

here is a simple test I did to see what happens when the data provider gets updated:

import fl.controls.*;
import fl.data.DataProvider;
import fl.controls.listClasses.CellRenderer;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

var tileList:TileList = new TileList ();
tileList.move(220,40);
tileList.setSize(215, 400);
tileList.columnWidth = 215;
tileList.rowHeight = 86;
tileList.direction = ScrollBarDirection.VERTICAL;
tileList.setStyle("cellRenderer", CustomImageCell);
addChild(tileList);

tileList.dataProvider = getRandomDP(10);
setTimeout(resetDP,3000);

function resetDP():void {
    tileList.dataProvider = getRandomDP(10);
}
function getRandomDP(size:int):DataProvider {
    var result:DataProvider = new DataProvider();
    for(var i:int = 0; i < size; i++)   result.addItem({label:'item'+i,source:'wrong.url/'+Math.random()});
    return result;
}

心连心