Flash Player 10 – fileReference.load()

Adobe extends the features on Flash Player in the every version and some of the features modernize the web development works. In Flash Player 10, it allows to access the local content via Browser Dialog, At the same time, we can not access the local content by action script from Flash Player without the knowledge of user, so its pretty secure. Usually, in order to load/display a image file (jpg or png) from local computer to Flash Player, we had to load that file to server, and then we need to download it from the server over HTTP to load into the Flash Player. Its pretty unnecessary process for just display a image into Flash Player.


You can see this additional method(load() as well as save()) in the FileReference Object. You just launch the Browser Dialog window by executing fileReference.browse() method, it allows you to select single file and click open and it fires the SELECT event. In the SELECT event handler, just call the fileReference.load() method, it loads the binary data of the selected file to the fileReference.data property. The fileReference.data is in the form of ByteArray, so we can easily load that bytes as  a source of an Image object. That's all, it will display the selected image.

Extension Checking

Since we have the binary content of the file which selected by Browser Dialog, we can check the original extension of the file by reading the binary data. Hence we can avoid the user to allow wrong file types, even though he/she manually change the extension of the file.

Secure File Transfer

Another secure way to transfer files from Desktop to Server via Flash environment. Since we have binary data for files we can easily transfer the file by using flash.net.Socket. So we can make a wonderful web client for transferring files via FTP(File Transfer Protocol). It could be pretty fast than HTTP and we can pause, resume the file while transferring. But we can not provide a nice user interface like other professional FTP client, since we can only input the files through Browser Dialog window. But you can achieve a Rich Internet FTP Client by developing the application on Adobe AIR.


I have just worked on the FileReference Object in last weekend and just  trying to load the local content to my flex application. It works perfect now.


Example - Flash Player 10 – fileReference.load()

Note: To view full source, right click this application and select the View Source from the context menu.

Setup and Requirements

Mainly it requires two things, one is Flash Player 10 and another one is Flex SDK 3.3. Here we need to setup one thing to work with real intelligence of the Flex Builder, since the default playerglobal.swc library of the SDK does not contain the fileReference.load() method and it will does not appear in the script. So you just need to remove playerglobal.swc and add the same library from here sdks/3.3/frameworks/libs/player/10/playerglobal.swc. And maker sure the Require Flash Player version is 10.0.0 in the HTML wrapper.

Please leave your comments if you have any trouble to work on this.

Be Sociable, Share!

Leave a Reply

Copyright © 2008-2010 K BalaSubramanian | Credits