André Michelle posted a few days ago a petition concerning the onSoundComplete event. This gave me an idea concerning the API we have currently in the Flash Player 9.

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 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.

Same limitation with the GIFPlayer library and ASZip.

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.

Please Adobe ;)

Update : This feature is available in the Flash Player 10 ;)