How to handle Unhandled #2044 errors from Flash tilelist when changing dataprovider?

孤街浪徒 提交于 2019-12-08 12:45:33

问题


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.

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.

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.

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

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

b


回答1:


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

Here's an example:

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;
}

HTH



来源:https://stackoverflow.com/questions/3214414/how-to-handle-unhandled-2044-errors-from-flash-tilelist-when-changing-dataprovi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!