Display progressive JPEG in Flash at boot time

I need to display a progressive JPEG image ( http://en.wikipedia.org/wiki/JPEG#JPEG_compression so as not to be confused with progressive JPEG display). Flash supports progressive JPEG loading, but I don’t know how to display it during loading. A quick googling search gives me progressive loading of serial JPEG and nothing more.

+8
flash actionscript-3 jpeg
source share
1 answer

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

+4
source share

All Articles