You need to convet the ByteArray to BitmapData to use it as image source. "loadBytes" method of the Loader class can be used for this.
loaderInfo:LoaderInfo = LoaderInfo(event.target);
// result: bitmapData
}Check this blog also
Thank you for the response.
It is certainly in the right direction.
However the files I have to display are .gif, .png, and .swf. Sadly, no bitmaps.
the import: mx.controls.Image;
I am trying to use that as a model. Maybe a bad idea.
So I have the contents of the files ( .gif, .png, .swf ) and I have the text file extension that the content came from.
I was hoping there is some "standard" or "easy for a novice program" way of presenting the bytearray and image-type to some subsystem and instruct it to display the image.
Hoping for too much?
What's the best approach ?
I have a problem before I can get to the problem I set out to find.
First for the original problem.
It seems as though the solution provided by Subeesh may very well work for the file types I am using.
But my problem now is that haveing retrieved the image contents by way of a web service, the image information seems to have been converted into some sort of HEX-ASCII representation. I presume this is a SOAP thing. Anyway, this can't be a unique problem.
So how do I convert the received block of "binary" data back to true binary?
So every second I run this code:
var image:String = BellImages.result[index].Image;
var decoder:Base64Decoder = new Base64Decoder();
decoder.decode( image );
decoded = decoder.toByteArray( );
BellImageMakeAssignment( decoded );
private function BellImageMakeAssignment( lclImage:ByteArray ):
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, BitMaploaderComplete);
From what I can tell, the bitmapData.draw fundtion is given the exact same data as was extracted from the database. Yet nothing appears!!!
I suspect the issue is because the entire class is defined as:
( public class BellBase extends Image )
Yet within the same class, the following line:
( source =
works just fine!
Ok, now what?
I dont know if that helps but here is how I get a dynamic image from the server into Flex:
var loader:URLLoader = new URLLoader();
loader.dataFormat = "binary";
var request:URLRequest =
private function completeHandler(event:Event):void
preview.data = event.target.data;
<mx:Panel borderStyle="outset" width="35%" height="100%" dropShadowVisible="true"
headerHeight="0" backgroundColor="#D6F3F6" paddingBottom="0">
<mx:Image width="228" height="576" id="preview"/>
I went reading through the source code for base class Image. Since my class is an extension of base class Image, I can change the "image" being displayed in 2 ways: 1 set variable "source" to the name of a file on the file server 2 set the variable "data" to a buffer containing the byte array contents of such a file. But to successfully manipulate the display using the "data" approach, one should also set "source" to null. so this works: var image:String = BellImages.result[index].Image; // an array or images returned by the web service, which read the images from the sql var decoder:Base64Decoder = new Base64Decoder(); var decoded:ByteArray; decoder.decode( image ); decoded = decoder.toByteArray( ); data = decoded; // set data variable of base class Image
<one should also set "source" to null
I am not doing that.
I assume what you mean by that is that you do not set "source" to null,
but that the image still displays.
That is true.
If you look into the source code for the definition of the "Image" class
you will see that it does things differently based on whether or not
"source" is set to null when you set the "data" value.
That is why I used the qualifier "should": having looked at the Image
source code, I want it to make decision A instead of decision B.
I suppose some day I will investigate what the difference is but for
now, things work as I want.
Having said that, I assume the Image constructor sets "source" to null
anyway, making it a moot point. So I assume that by not explicitly
setting "source" you leave it at the default value of null.