It will look something like this:
// the loader containing the image var loading:Boolean = false; var loader:Loader = new Loader(); addChild(loader); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function() { loading = false; trace(loader.width, loader.height); }); var bytes:ByteArray = new ByteArray(); var stream:URLStream = new URLStream(); stream.addEventListener(ProgressEvent.PROGRESS, onProgress); stream.addEventListener(Event.COMPLETE, onProgress); stream.load(new URLRequest(imageURL)); function onProgress(e:Event):void { stream.readBytes(bytes, bytes.length); if((bytes.length > 4096 && !loading) || e.type == Event.COMPLETE) { loading = true; loader.loadBytes(bytes); } }
Note that the loadBytes process is asynchronous. Also, if you try it with unparseable bytearray (usually the first onProgress calls when there is not enough image data to process), it fails, so you need to somehow ensure that you have enough data ... in this case I used if (bytes.length> 4096) ;)
Cay
source share