views:

35

answers:

1

Hi all -

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  A: 

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

George Profenza
I am doing this exactly. The handler catches IOErrors while the tile list is loading, but if I change the dataprovider I then get unhandled ones as if the loaders that should have been disposed of during the dataprovider change are then sending IOErrorEvents that are no longer handled because the loader itself is gone.
WillyCornbread
@WillyCornbread Is that what you mean by changing the dataprovider ? In my tiny test, even if the data provider changes,the behaviour is the same.
George Profenza
George - The solution was indeed in your original answer. I was adding my own IORErrorEvent handler to the protected loader, but NOT overriding the protected 'handleErrorEvent' method of the loader. Once I used an override of that, the problem stopped. Thanks so much for the assistance.
WillyCornbread
glad that got sorted out!
George Profenza
@WillyCornbread Oh, I stumbled on this question: http://stackoverflow.com/questions/101532/how-to-catch-all-exceptions-in-flex "Global error handling is now supported in Flash 10.1 and AIR 2.0 (both in beta), and is achieved by subscribing the UNCAUGHT_ERROR event of LoaderInfo.uncaughtErrorEvents. The following code is taken from the code sample on livedocs:" ...good to know :)
George Profenza