One of the most disappointing thing we have when playing with bytes in the Flash Player 9 is the FileReference API. Let's say you call the FileReference.browse() method to select a file.
Once selected, you have no way to get a ByteArray from it directly.
Of course you have the following solution :
First, you have to upload the file to your server, then you have to download it with the flash.net.URLLoader class as a binary file (URLLoaderDataFormat.BINARY), and then you'll get the bytes.
This means that for any Flash online image editing application, you will have to upload your bitmap first, and then download it before having fun with the application. I would like to introduce a new method in the AlivePDF library so that you can embed any image stream easily. The current Flash Player doesn't facilitate that.
Now, even worse.
There is no way to save a generated ByteArray on the hard disk through the FileReference API. Once again, you will have to upload it, and then ask to a server side script to spit it out back to the browser with appropriate headers so that it shows a download box window.
But guess who does allow all of this ?
Here is how you would get the bytes from a selected file in Silverlight 1.1 with the OpenFileDialog class :
Stream fileStream = browseDialog.SelectedFile.OpenRead(); byte funkyBytes = new byte[fileStream .Length]; fileStream.Read(funkyBytes, 0, (int)fileStream.Length);
The final release of Silverlight 1.1 will also include a SaveFileDialog class. This should allow us to save runtime streams locally through a save-as dialog window.
As would say André, please leave a comment. Let's bring that in the Flash Player 10, that would rock.
Update : This feature is available in the Flash Player 10