Skip to main content
Known Participant
February 26, 2011
Answered

User generated file?

  • February 26, 2011
  • 3 replies
  • 2065 views

Yes, I'm curious to know whether it's possible to have a user generate a file (.txt is fine), using a flash module i created, and based on their answers to certain questions within my flash module, all created in flash cs3. Your thoughts?

thanks,

~s

This topic has been closed for replies.
Correct answer Kenneth Kawamoto

Yes. You need Flash Player 10 or later.

A quick example:

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.net.FileReference;

    public class ClickToSaveAFile extends Sprite {
        private var _filereference:FileReference;
       
        public function ClickToSaveAFile():void {
            stage.addEventListener(MouseEvent.CLICK, click);
        }
       
        private function click(e:MouseEvent):void {
            saveTextFile();
        }
       
        private function saveTextFile():void {
            _filereference = new FileReference();
            _filereference.addEventListener(Event.COMPLETE, fileSaveComplete, false, 0, true);
            _filereference.addEventListener(Event.CANCEL, fileSaveCancel, false, 0, true);
            _filereference.addEventListener(IOErrorEvent.IO_ERROR, fileSaveError, false, 0, true);
            _filereference.save("Hello world!", "example.txt");
        }
       
        private function fileSaveComplete(e:Event):void {
            trace("File saved.");
            _filereference = null;
        }
       
        private function fileSaveCancel(e:Event):void {
            trace("File save cancelled.");
            _filereference = null;
        }
       
        private function fileSaveError(e:IOErrorEvent):void {
            trace("File save error:", e.text);
            _filereference = null;
        }
    }
}

3 replies

Kenneth Kawamoto
Community Expert
Kenneth KawamotoCommunity ExpertCorrect answer
Community Expert
February 26, 2011

Yes. You need Flash Player 10 or later.

A quick example:

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.net.FileReference;

    public class ClickToSaveAFile extends Sprite {
        private var _filereference:FileReference;
       
        public function ClickToSaveAFile():void {
            stage.addEventListener(MouseEvent.CLICK, click);
        }
       
        private function click(e:MouseEvent):void {
            saveTextFile();
        }
       
        private function saveTextFile():void {
            _filereference = new FileReference();
            _filereference.addEventListener(Event.COMPLETE, fileSaveComplete, false, 0, true);
            _filereference.addEventListener(Event.CANCEL, fileSaveCancel, false, 0, true);
            _filereference.addEventListener(IOErrorEvent.IO_ERROR, fileSaveError, false, 0, true);
            _filereference.save("Hello world!", "example.txt");
        }
       
        private function fileSaveComplete(e:Event):void {
            trace("File saved.");
            _filereference = null;
        }
       
        private function fileSaveCancel(e:Event):void {
            trace("File save cancelled.");
            _filereference = null;
        }
       
        private function fileSaveError(e:IOErrorEvent):void {
            trace("File save error:", e.text);
            _filereference = null;
        }
    }
}
Participating Frequently
February 26, 2011

Hmm you may be onto something kennethkawamoto2. I'm going to see if i can write some bytes.

Ben Smith

ActionScript Technologist

@fezec | Member of Adobe's Community Professionals

Participating Frequently
February 26, 2011

not in as3 unless you're making an air file.

You need to incorporate some php or .net to save their file to .txt , and then they can download it.

Ned Murphy
Legend
February 26, 2011

Flash cannot create files, so you would need to have some other resource such as PHP to manage the saving of any new file