FileReference vs File? - actionscript-3

I want to make a Flash app in which the user can load and save files from and to their local hard drive. While I've often done this in AIR apps using the File and FileStream classes, I haven't done so before in an SWF.
From what I know the FileReference class is used for this, although it seems to have some restrictions due to security risks. I'd like to know what the main differences are between using the FileReference class and using the File and FileStream classes to load and save files.

The File class extends the FileReference.
FileReference is safe to be used in the FlashPlayer (in the browser) because it won't let you modify the files in the user machine.
If you want to open a file, you need to as for the user to open it for you with: FileReference.browse().
To save a file, you need to ask the user to save it: FileReference.save()
With File class you can open, modify and save files without those dialogs.
Furthermore, the File class gives you a bunch of useful properties like: File.desktopDirectory, File.documentsDirectory and such.
You can check if a file exists with the exists property and have a much restriction when manipulating file in the user file system.
You can read more about the FileReference and File classes in the docs.

Related

AS3 write string to an existing text file

I'm running my program on AIR. I want my game to save the high score to a text file so it can be stored when the program is closed. I've tried using filestreams, however I've found that the application directory is read only. Is there a better way to do this?
The AIR application storage directory is designed for saving these sorts of preferences and user settings:
For every AIR application, there is a unique associated path that
defines the application storage directory. This directory is unique to
each application and user. You can use this directory to store
user-specific, application-specific data (such as user data or
preferences files).
Access it through the File class:
var file:File = File.applicationStorageDirectory;
file = file.resolvePath("prefs.xml");
See also: Reading from and writing to an XML preferences file
The only caveat I have found with using this directory is that it does not get removed when the AIR app is uninstalled using the .air installer/uninstaller.

Actionscript 3.0(Adobe Flash CS4) Loading external .as files without knowing name of .as file

I want to know how to load external class files(.as files) in actionscript but don't have to know the class file's name. Think of it like loading mods in minecraft with forge mod loader, it doesn't know the main class of the mod's file name, yet it successfully loads the mod. I want to know if something like this is possible in actionscript 3.0 because I feel like making a tower defense game that isn't like the others out there but have it so it can be modded and have mods loaded but of course I have to load the class file without knowing the class file's name.
Note: I don't got access to Adobe Air so I can't use anything that requires Adobe Air.
You want to load a particular .as file AFTER or BEFORE compilation? After the compilation it is hardly possible - the file would not be compiled and therefore it would be useless. Why don't you use a swf or some kind of XML/JSON with settings in that case? Before the compilation you would still need to identify it by it's package name/name.
Basically, you want a plugin management system.
In AS3, it is not possible to "load" a .as file on execution, because it is a (uncompiled) source file. But, it is possible to load another swf and to use the classes within it.
Your process should probably be something like this :
Get a list of the plugins/addons. If you were using AIR, it would have been possible by browsing the content of a folder. Since you're not, you'll probably need to use a listing file (basically, a file that say "Here's the list&path of the plugins you need to load".
Load each swf file
(possibly) call a initialization method for each plugin.
You may wish to look into the way OSMF manages plugins, for example : http://osmf.org/dev/osmf/OtherPDFs/osmf_plugin_dev_guide.pdf

How to I keep track of changes in FLA file (via version control)

I have all of my files in version control (SVN subversion). FLA file is not a text file, so when I change it and check it in, there isn't a way to see what has changed inside of FLA.
Is there a way to keep track of changes to FLA file and it's contents?
Flash CS5 has introduced a new file format called XFL which has been designed for use with version control systems. This format basically splits up your FLA file into a series of separate XML data files (all contained within the one folder) which means version control systems can accurately determine what parts of the file have changed.
Simply go to File > Save AS, and select xfl from the drop-down list.
If you're using anything before CS5, then unfortunately there is no similar way to accomplish this task. I will add, however, that if this is the case, then you can try and mitigate this problem by keeping all your code in an external AS file and load any data from external xml/image/etc. files. This way, there is at least some degree of tracking for certain parts of your project.

Flex swf write to local file if given authorization by the end user

Is it possible to write to a local file 'example.txt' from a Flex swf? FileStream class is available in Adobe AIR, not in Flex. I want to write to from a swf,not AIR application.
I am developing a kiosk type application which has to log user interaction data to a text file on the machine.
Is there a code example for doing this?
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf6167e-7fff.html#WS2db454920e96a9e51e63e3d11c0bf6167e-7ff9
You can use FileReference to save a file with user confirmation. You can also use FileReference to load a file specified by the user. Or, you can use a SharedObject to save information without a dialog.

Is it possible to convert an XML file created in actionscript to a FileReference object?

I have a working s3 uploader in actionscript that uses the FileReference class so a user can browse for files to upload when he/she clicks on the upload button.
I have a web application and I want the user to have his/her configuration saved to s3 as an XML file when they hit the save button, so the "save" button will trigger the upload. However, i cant figure out a way to add the XML file to the FileReference variable I create. I was looking at the File class but that appears to be only usable in AIR.
Is it possible to create a FileReference object based off of an XML file that actionscript creates within the application without browsing for a file using FileReference.browse(); ?
Thanks
The answer to my original question is "no". According to this article by Mike Chambers, you cant.
It is apparently a sandbox issue so that a malicious flash program will not be able to do anything related to saving files without a users permission.