Amazing New Feature for Flash 10 – FileReference Runtime Access

I have been consuming all the great additions to Flash 10 this weekend and one that really jumps out after you get past the visual, text and sound features (which are spectacular btw and most of what the community was asking for). But one feature snuck by, this is the one that ByteArray (Thibault Imbert) mentions/pointed out for managing files directly within Flash.

File Reference runtime access — Bring users into the experience by letting them load files into your RIA. You can work with the content at runtime and even save it back when you are done through the browse dialog box. Files can be accessed as a byteArray or text using a convenient API in ActionScript without round-tripping to the server. You no longer have to know a server language or have access to a server to load or save files at runtime.

This greatly lowers the bar to using Flash as a photo editor, document manager, customized application experiences, marking up content and saving locally, all without the need for server side script. I am a big fan of server side technologies and develop with them but even for bettering performance this could be huge.

Scenarios where this might be useful is editing applications, note taking (download a book with your notes), editors for docs/games/3d/textures,,, the possibilities are endless really.

Flash 9 just got mainstream and production ready (flash 9 penetration) at the tail end of last year but there are so many great things in the new version that I hope it comes out very soon. Flash it turning into quite a platform.

Alternativa Platform also has updated their engine for Flash 10 already (they must have had some inside early accessibility to it) and there are great possibilities here.

It is only beta (Flash 10) but there are great market opportunities to prepare for when this launches. Keep your eye on where the puck will be, not where it is currently at. I was concerned when Adobe bought Macromedia and the future of Flash but it appears they are taking this bull by the horns.

If you are ready to play with Flash 10 here is Flex and FlashDevelop updates to help you get started.

Also here is some code posted at ByteArray from Pleh for testing the new FileReference runtime access, usage is extremely simple and rests on this

var data:ByteArray = fileRef['data'];

/*
  FileReference Load Example By Pleh 17/05/08
*/

package {
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.FileReference;
	import flash.net.FileFilter;
	import flash.utils.ByteArray;

	public class Flash10Test extends Sprite
	{
		private var fileRef:FileReference;

		public function Flash10Test()
		{
			fileRef = new FileReference();
			fileRef.addEventListener(Event.SELECT, selectFile);
			fileRef.addEventListener(Event.OPEN, openFile);
			stage.addEventListener(MouseEvent.CLICK,stageClick);
		}

		private function selectFile(e:Event):void {
			fileRef['load']();
		}

		private function openFile(e:Event):void {
			var data:ByteArray = fileRef['data'];
			var loader:Loader = new Loader();
			loader.loadBytes(data);
			addChild(loader);
		}

		private function stageClick(e:Event):void{
			fileRef.browse([new FileFilter("All Formats (*.jpg,*.gif,*.png,*.swf)", "*.jpg;*.gif;*.png;*.swf", "JPEG;jp2_;GIFF;SWFL")]);
		}

	}
}

Advertisements

30 Responses to “Amazing New Feature for Flash 10 – FileReference Runtime Access”

  1. » Blog Archive » Flash Player 10 - Astro Says:

    […] on Adobe Labs How to compile for Astro using Flex 3 Adobe make some noise Flash 10 Drawing API FileReference Runtime Access FDT + Astro = […]

  2. Saeed Ashour Says:

    Hi ….

    Thanks for the info but i need to ask you about the plugins that you use to warp you actionscript 3.0 code in this post , i need to know from where i can download it if you do n’t mind of course .

  3. A-SFUG: Another Singapore Flash User Group » New features in Flash 10 Says:

    […] FileReference Runtime Access: Now you can directly work on user’s local files. Previously, you need to upload a file to the server, download the file from server and then you can edit it. It’s much easier now. For more info, please refer to Draw Lgoic’s blog. […]

  4. Tech Per Says:

    I thought this to be a great feature add too. Have you got any information on the security part of this? Flash apps live in a sandbox like applets do, and applets ask the user for permission, when accessing. There must be something like it in the flashplayer!? Also, as a user, you can grant applets extra rights, when/if it is signed. Can you sign a flash application?

  5. drawk Says:

    @Saeed This uses Genshi highlighting

    @Tech. I thought about this as well but this is mostly a local process. So when you upload a file it really is just happening locally in the flash player running on your machine within the sandbox. Then when you request a download it really is just pulling from the sandbox on your local machine. That is one thing about flash apps that this a little less troublesome when it comes to security. I am sure there are some potential holes but again it can only happen locally. When the user decides to push to the server that is a different process than the local sandbox.

  6. Flo Says:

    Hi,

    here is my first example using the new File Reference API:
    http://www.video-flash.de/index/flash-player-10-demo-dateien-lokal-laden-und-abspeichern/

    Saving is also very easy: myFileRef.save(myByteArray);

    Florian

  7. drawk Says:

    Nice Flo,

    This feature has so many possibilities it is just hard to wait for it to become mainstream – maybe 6 months to a year? I guess there will be plenty of time to get these things lined up for the release.

  8. Amazing New Feature for Flash 10 Says:

    […] Interesting developments on the new Flash Player Version 10 have bubbled up. No need to repost the info again since you can read it at the draw.logic Blog http://drawlogic.com/2008/05/17/amazing-new-feature-for-flash-10/ […]

  9. certxg Says:

    Hi, I tried this new feature with FileReference:

    fileRef[‘load’]();
    var data:ByteArray = fileRef[‘data’];

    and found out it could only handle 512K. Would somebody verify that there is a file size limit? And if there is, how would we be able to expand it?

    thanks,

    -certxg

  10. drawk Says:

    Hey certxg nice call, will have to look into this. It is beta and should be configurable but it also might be related to your local storage i.e. flash storage. Try right clicking on the flash, then going to ‘settings’ then local storage (the folder) then setting it to a realy high amount or unlimited. I am sure it uses this space to save locally in the sandbox. We can thank Jeremy Allaire and the MX product line for that which was added to support streaming camera and shared objects stored outside the internet cache but still in a sandbox.

  11. certxg Says:

    Thanks drawk. I guess I’m still confused. I’m on windows vista, and installed with flash player 10 beta (an activeX). Where do I go to get to the local flash storage?

    thanks a bunch again,

    -certxg

  12. drawk Says:

    By default is it installed in the windows directory but to modify settings just right click on any flash you are making and testing, then go to settings in the right click menu, then click on the little folder icon which brings up the local storage tab. Then you can up that. By default I think it is 100KB, up it to much higher or unlimited.

    There are some images and docs here to help: http://www.macromedia.com/support/documentation/en/flashplayer/help/help02.html

  13. certxg Says:

    alright, I added the following code, and when the secure panel comes up I set both the local and global storages to unlimited, yet it seems still not working:

    public function initApp():void {
    Security.allowDomain(“*”);
    Security.showSettings(SecurityPanel.LOCAL_STORAGE);
    Security.showSettings(SecurityPanel.SETTINGS_MANAGER);
    }

    anything I’m still missing?
    thanks for taking your time,

    -certxg

  14. drawk Says:

    hrm that is not good. Looks like you have it all right and if you put to unlimited I am not sure why it isn’t taking anything bigger. Let’s hope it is a beta issue and resolves. You might want to enter it as a bug/feature. I want to look into this but probably wont’ have time til this weekend.

  15. certxg Says:

    ok, I’ll come back and check by this weekend, hopefully you can help find a fix for that by then.

    appreciated your efforts,

    -certxg

  16. Devil Says:

    hi!
    I m in a problem please help me!
    I hv to make an application for downloading a folder from the server to the client I m not getting nething abt hw to do that, can u help me out.

    thanks for ne help in advance.

  17. Devil Says:

    one more thing I forgot to write I m working in flex and action script 3

  18. certxg Says:

    don’t know about how to do a folder-downloading recursively. but you can use FileReferenceList to do multiple file download.

    if that’s ok with you, you can use the code sample here and just change the FileReference.upload to download with the server URLRequest:

    http://drawlogic.com/2007/08/02/uploading-multiple-selectable-files-with-flash9-and-as3/

  19. certxg Says:

    no, it won’t work. forget about what I just said. sorry.

  20. ryan Says:

    Yeh certxg,

    I would do this now but I have my production machine on Flash 9 for testing. I need to get this tested on my Flash 10 machine. If there is a limit I am sure that is a beta issue where they haven’t hooked it to the local storage just yet.

  21. Devil Says:

    the problem is I m able to download file from the internet but not from the local server beside me….can you tell me what URL should be used if IP is 172.18.100.126 and file is example.txt……………..and moreover where this file should be kept on the server

  22. certxg Says:

    hello drawk, got any chance to look into the file size limit with the FileReference class?

    how do i submit it as a bug/feature if there is no way to get around it?

    thanks,

    -certxg

  23. Pathfinder Development » Flash 10 - FileReference Runtime Access Says:

    […] This is what I was waiting for – FileReference Runtime Access! To quote the original blog post: […]

  24. Kuy Says:

    Be sure to wait for the Event.COMPLETE event instead of Event.OPEN before you try to access the .data property. That will fix your limited-file-size problems.

  25. certxg Says:

    thanks Kuy. I’ll have a try and see how it goes.

    -certxg

  26. A-SFUG: New features in Flash 10 Says:

    […] FileReference Runtime Access: Now you can directly work on user’s local files. Previously, you need to upload a file to the server, download the file from server and then you can edit it. It’s much easier now. For more info, please refer to Draw Lgoic’s blog. […]

  27. grega Says:

    File size limit: well it’s not about local storage (it seems), anybody solved this issue? On my computer i can’t load files >1MB or so.

  28. Flash Player 10 New Features | experimo Says:

    […] draw-logic – new filereference methods […]

  29. SIR MAJKEL Says:

    Hi Drawk!
    This code it doesn’t work, becouse You forgot about completeLoadHandler.
    Some like this:

    fileRef.addEventListener(Event.COMPLETE, comleteLoadHandler);

    private function comleteLoadHandler(e:Event):void {
    var data:ByteArray = e.target.data;
    var loader:Loader = new Loader();
    loader.loadBytes(data);
    addChild(loader);
    }
    before load complete You can’t see fileRef.data property 🙂

  30. Flash 10 Officially Released « [ draw.logic ] Says:

    […] 10 is great news. There are so many things in it from a new data structure (Vector), to local FileReference, to Matrix and 3D helpers, to speed improvements and video enhancements being able to play other […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: