Also I discovered something new.
When I try to draw the byteArray onto the sprite, the result is messed up pixels. See the attachment. But the UILoader loads the same byte array fine. How can this be?
I'm not sure what you're trying to do here...but you cannot use the binary data you loaded with a URLLoader as bitmapData if it was loaded from a png or jpeg for example. Those file formats need to be decoded into bitmapData - using the player's native support for that seems best.
There does seem to be a frame delay with the loadBytes method and you can't catch it using the COMPLETE event, as you say.
I got it working like this (perhaps there is a better way than using the enterFrame, but I just did this quickly to check)
var $image:Sprite=new Sprite();
addChild($image);
var myBitmapData:BitmapData;
var imageLoader:Loader = new Loader()
var dataLoader:URLLoader=new URLLoader();
dataLoader.dataFormat = flash.net.URLLoaderDataFormat.BINARY
dataLoader.addEventListener(Event.COMPLETE,completeHandler)
function loadImage(url:String):void{
var req:URLRequest=new URLRequest(url);
dataLoader.load(req)
}
function completeHandler(e:Event):void{
//use enterFrame to check for loaded content
imageLoader.addEventListener(Event.ENTER_FRAME,imageDecodeHandler);
imageLoader.loadBytes(e.currentTarget.data);
}
function imageDecodeHandler(e:Event):void{
if (imageLoader.content) {
trace('loaded')
imageLoader.removeEventListener(Event.ENTER_FRAME,imageDecodeHandler);
myBitmapData = Bitmap(imageLoader.content).bitmapData;
//imageLoader.content width and height available now as well as myBitmapdata.rect etc
$image.graphics.beginBitmapFill(myBitmapData,null,true,true);
$image.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
$image.graphics.endFill()
} else {
trace('not yet loaded')
}
}
//substitute a local image file here:
loadImage("46.png")