Recently I had to load in images from database references that were pointing to a .net serverside script. This path ended with something like ImageHandler.ashx?id=164
When I tried to load this in with my standard ImageLoader it didn’t work because it was coming back as binary and I was getting a reference error about the URL type not being found. I think it was
Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.
The way to get around this is a little strange and involves 2 loading processes. The first one loads in the data but set as
_loader.dataFormat = URLLoaderDataFormat.BINARY;
Then once this has loaded we ‘load’ the ByteArray that is returned into a loader and proceed as normal:
public function loadBinaryJPG(_path:String):void
{
_loader = new URLLoader();
_loader.addEventListener(Event.COMPLETE, _onLoadInit);
// set the dataFormat to binary
_loader.dataFormat = URLLoaderDataFormat.BINARY;
_loader.load(new URLRequest(_path));
}
private function _onLoadInit(e:Event):void
{
_loader.removeEventListener(Event.COMPLETE, _onLoadInit);
// once the binary data has loaded, check that there
// is data there and load that into a Loader
var _l2:Loader = new Loader();
_l2.contentLoaderInfo.addEventListener(Event.COMPLETE, _blComp);
var _byteArr:ByteArray = new ByteArray();
_byteArr = _loader.data;
// check that data was returned
if(_byteArr.length != 0)
{
_l2.loadBytes(_loader.data);
} else {
// generate error message
}
}
private function _blComp(e:Event):void
{
// deal with binary data that is in the loader (e.target)
_bmdata = new BitmapData(114, 87, false, 0xFFFFFF);
_bmdata = (e.target.content).bitmapData;
_bm = new Bitmap(_bmdata, "auto", true);
// deal with loaded Bitmap
}
Thanks, Dan! I had the same problem and solved it by using your suggestion!
Thanks again!
Hi there,
I need to load the jpg returned from this url: “http://www.optusmusicstore.com/handlers/thumbnail.ashx?id=1927860&tp=138”
I get the same error but was having high hope in your script but I still get that nasty error, any ideas why?
Thanks! F
Hi Fabrice, I attempted to get this to work but discovered that this image isn’t really a loaded jpg, but a PNG somehow constructed from CSS that in turn as comes from HTML. Tracing out the byte array from the initial load was HTML, not image data, but if you ‘View Generated Source’ on the image, you can see that it is done with CSS. I don’t know if there is a way to load this image in Flash so sorry I can’t help!
Thanks Dan for your insight!
Dan sorry for the double post, just out of interest how did you discover that the image was a png constructed from CSS?
Hi Fabrice, using Firefox and the Web Developer extension I selected ‘View Generated Source’ and some CSS was there that had a PNG in it. Today the ‘View Generated Source’ is only showing HTML. I don’t know why this would be giving a different result on different days.
However I have managed to get an example working though which should please you. 🙂
Download it here
Hi Daniel,
Thanks again so much for taking the time to help! unfortunately it still doesn’t work even with your example.
Tracing the _byteArr I get that message: “Image format is not supported by this device” and then the error message: “Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.”
How did you get it working!! 🙂
hi,
i too get this Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.”
i am trying to load bytearray as image in spark image control in flex but that error message is occurred.