views:

57

answers:

4

Hi,

I'm looking to do some development in flash 10, specifically for the new file api (reading/writing files on the user's local machine). What do I need to develop for flash 10, just Flash cs4?:

http://tryit.adobe.com/us/cs4/flash/c/?sdid=ETJMX&

or is there some other ide? All I'm really interested in doing is:

  1. Make a small swf file which reads a file on the user's machine
  2. I will host it in an html file
  3. When file read is done, I just want to send its contents as a string to a javascript function for further processing.

Not sure if I can get away with the free adobe air thing for this? I need it to run in a webpage but I don't intend to do any more development outside of the above,

Thanks

A: 

You could use Flex Builder instead which is more of a true IDE and more programmer oriented, where as Flash CS4 is more designer oriented.

AaronLS
A: 

It's absolutely possible to write and compile SWFs using free tools, you can use the free Flex SDK to compile your code, and an editor of your choice. Flashdevelop, is an excellent actionscript editor, and integrates nicely with the Flex SDK compiler.

These tools will let you do all you want to do.

If you're a student or unemployed, you can even pick up the Flash Builder IDE for free.

Kristian J.
+2  A: 

If you want a free solution:

Download Flex SDK, then download FlashDevelop

It's perfect for coding.

As security restriction, every time you want to save a file it pops up the Save As dialog box asking the user where to save it. For loading, on user input, you can call the FileReference.browse(); You can learn more about this class, here.

Also, you can use AIR to save the file: (AIR is flash compiled for desktop, you can't use it for web)

import flash.filesystem.*;
import flash.events.Event;

var docsDir:File = File.documentsDirectory;
try{
    docsDir.browseForSave("Save As");
    docsDir.addEventListener(Event.SELECT, saveData);
}catch (error:Error){
    trace("Failed:", error.message);
}
function saveData(event:Event):void {
    var newFile:File = event.target as File;
    var str:String = "Hello.";
    if (!newFile.exists){
        var stream:FileStream = new FileStream();
        stream.open(newFile, FileMode.WRITE);
        stream.writeUTFBytes(str);
        stream.close();
    }
}
M28
Yes, starting with Flash 10 you can read a file from the user's workstation directly, with certain security restrictions, of course.
Cameron
I am not sure about this, but I thought we are allowed with Flash 10 to read and write files so long as the user clicks a button and picks a file from their machine. Definitely security risks involved and I wouldn't be surprised if this isn't allowed at all, but I *thought* it is now, not sure.
I never tried that, but I think it is possible, but you'll need to prompt the user with a Open File... dialog box.
M28
It's possible, I've used it (both saving and loading) :-) As another security restriction, every time you want to save a file it pops up the Save As dialog box asking the user where to save it. For loading, on user input, you can call the `FileReference.browse()` function: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/FileReference.html#browse()
Cameron
Thank you! Added to the answer :D
M28
Added yet moar things :D
M28
+1  A: 

Yes, you have all you need to create Flash 10 SWFs with the Flash CS4 authoring tool, however:

As AaronLS points out, Flash CS4 is not a particularly good code IDE (it is more aimed at designers). As an alternative to Flex Builder, there is an open source Flash IDE, called FlashDevelop, that is quite good. It still requires CS4 (or some other AS3 compiler, like the Flex SDK, which is free) to compile the code, but you get the benefit of a nicer coding environment.

For such a simple task that only involves code (no design), the Flash authoring environment might be overkill, although it is the simplest way to proceed.

You might also want to check out haXe (a language), which can compile to SWFs directly, or compile to AS3 code. For this simple application, I would suggest using haXe, since it is free and easy to use for simple SWFs (no mucking about with MXML, etc). However, haXe is not everyone's cup of tea.

Cameron