Flash Player 10 and AIR allow loading files from your local system as well as saving files. Once the files are loaded you have access to the ByteArray.
Convert ByteArray into an image
You can easily convert the ByteArray into an image:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void
{
event.currentTarget.removeEventListener(event.type, arguments.callee);
image.source=loader.content;
});
loader.loadBytes(event.file.fileContent);
Play ByteArray
Unfortunately, you cannot set the bytes of a video stream through the NetStream Object. What you can do is write the URLStream’s bytes to a local file, and then pass that file to the NetStream object. You can do a workaround such as writing out the URLStream’s bytes as they come in with the help of the “append” method.
What it means is that you cannot play ByteArray in AIR or Flex Application. I know that that feature is on the Adobe’s team list but until they adjust the code you will have to find a workaround.






















I have files that are stored on a secure server. Our flex app can retrieve theses file by making a call to our server api (managed by blazeds). The api will send these files to the client in the form of a ByteArray. In our flex app we need to provide a utility to enable the user to view these files. It appears that we are out of luck here based on your comments. Is there no work around you can think of? Writing the stream to a local file in not an option in our case.
Thanks for any advise.
What type of format are the original files? are you using AIR?
Hi
Can I write a series of bytes in python or C to the disk and then make flash load the file and interpret it as an image?
It should work!
Hey I’m trying desperately to load an image into flex from a byteArray and for the life of me I cannot seem to get it to work. I have code that uses a FileReference to browse for a *.png file, and then on completion it will set the img.source = fileReference.data. This works great! The fileReference.data is in the form of a byteArray.
I then use Cairngorm to save that byteArray to the database using Coldfusion. That part works perfectly as well.
I can the retrieve the byteArray, pass it back to flex, verify that all the properties of the byteArray are exactly the same as the properties were when the image worked, and then assign it to the img.source, and I get a broken image.
if I do this:
if(this.chat_queue.company_logo.length > 0){
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void {
this.imgLogo.source = e.currentTarget.content;
});
_loader.loadBytes(new PNGEncoder().encodeByteArray(this.chat_queue.company_logo,90,43));
}
Then I get “Error 2030: End of file was encountered.”
If I try this: }
if(this.chat_queue.company_logo.length > 0){
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void {
this.imgLogo.source = e.currentTarget.content;
});
_loader.loadBytes(this.chat_queue.company_logo);
}
Then I get “Error #2124: Loaded file is an unknown type.”
I’m at my wits end. Any help would be greatly appreciated.
Sounds like when the data is inserted into the database some characters are changing.. I would compare the data from the database…