>After reading some previous posts, it appears that the best way to convert a 
>byte array into a >Bitmap is though the loader class...


>In my debugging it fails silently, but I get the follow message when I try to 
>look into the >vars (Error: Error #2099: The loading object is not 
>sufficiently loaded to provide this >information.)  Also the "content" 
>property is "null" even though the bytes are fully loaded.

>Is there another better way to do this.  I have been struggling with this all 
>day.

>Thanks, Kevin


Hi Kevin, I feel your pain! Having been through this one before ...

It doesn't work quite as one (well, myself in any case) would expect on first 
look.

Even when feeding in an already complete byteArray, you still have to listen 
for the load Complete event.
Up until that event, loader.content remains null.

_jpgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,jpgCompleteHandler);

try something like this (it could do with an IoError event listener as 
well,perhaps?) :

private var _ldr:Loader

private function myTest():void{
                //get ByteArray from Image Component content
                var testBM:Bitmap = testImg.content as Bitmap;
                var myByte:ByteArray = new 
JPEGEncoder().encode(testBM.bitmapData);
                //convert ByteArray to Bitmap
                _ldr = new Loader();
                _ldr.addEventListener(Event.COMPLETE,bitmapLoaded);
                _ldr.loadBytes(myByte);
}

private function bitmapLoaded(event:Event)
{
        _ldr.removeEventListener(Event.COMPLETE,bitmapLoaded)
        //reset source
        myImage.source = _ldr.content;
}

(Personally I like to keep a permanent reference to the loader, rather than 
casting it from the event.target)

Alex, I think it does work as it's meant to, but I would really like to have a 
means to do the same byteArray > bitmapData conversion synchronously without 
the listener.
If anyone can help with that, then please let me know!

Also, I did have some difficulty with the docs in this respect, a small sample 
like the above would help greatly imho.

Jim.

______________________________________________________________________
This communication is from Primal Pictures Ltd., a company registered in 
England and Wales with registration No. 02622298 and registered office: 4th 
Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT 
registration No. 648874577.

This e-mail is confidential and may be privileged. It may be read, copied and 
used only by the intended recipient. If you have received it in error, please 
contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 
1010. Please then delete the e-mail and do not disclose its contents to any 
person.
This email has been scanned for Primal Pictures by the MessageLabs Email 
Security System.
______________________________________________________________________

Reply via email to