1
votes

I am using adobe flash cs6 for creating a desktop application. In that application iam using flash.filesystem.filestream to save a text file (I dont want to use FileReference because I don't want show the save dialog box ) When I call the new FileStream() in the exported .swf or .exe file, the app stopped running and it closes the window. here is my sample code while executing this line var fileStream : FileStream = new FileStream(); the window closed automatically but this code work fine in Preview mode ( ctrl + Enter) iam using Target: AIR 2.5; Script: ActionScript 3.0 in publish settings.

sample.as

package{
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;    

public class SampleClass {
    public function generateReport (text : String) : void
    { 
        var fileMode:String = (FileMode.APPEND);
        var fileStream : FileStream = new FileStream();
        var file:File = File.desktopDirectory.resolvePath("sample.txt");
        fileStream.open (file, fileMode);
        fileStream.writeMultiByte (text, File.systemCharset);
        fileStream.close ();
    }

}

}

Is there any way to solve this problem ? Thank you very much!

Pravin

1
Got any (minimal) testable code of your setup? Easier to test same code ourselves to advise. Does it work if .exe is opened using "run as Admin" option? Sounds like a permissions issue of some kind. PS: Also you can update to latest AIR SDK even in older CS6. - VC.One
No, It does n't works if i opened my .exe file using "Run as admin" - Pravin kumar
update your Air to at least air 3.0, also make sure creating exe with publish button. - payam_sbr
I tested your code. The exe did not crash or close for me but also it did not create a text file on Desktop (the Debugger test worked fine as same for you). I think your problem is this line : .writeMultiByte (text, File.systemCharset); once it was changed, the exe made a text file. I'll expand this into an Answer soon. Why File.systemCharset? Are you writing non-English alpahabet characters? - VC.One
No, i have appended only English alphabets and a special symbol comma i have tested by commenting all my line except var fileStream : FileStream = new FileStream();. while executing this line my window gets closed while running .exe file but in debugger mode it works fine. i think i have missed something while publishing. - Pravin kumar

1 Answers

1
votes

I have no idea what content of text is, but from that .writeMultiByte (text, File.systemCharset); I assume you wanted to write non-English alphabetic chars?

Best just use .writeUTFBytes since that handles both English & foreign alphabets.

Anycase... See if this code re-fix SampleClass.as works for you (tested with no crashing .exe) :

package{

import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;

import flash.display.MovieClip;

public class SampleClass extends MovieClip {

    public function SampleClass ()
    {
        generateReport("test Chinese : 你好 世界 ... test Urdu : ہیلو دنیا ... test Russian : Привет мир");
    }

    public function generateReport (text : String) : void
    { 
        var fileMode:String = "append"; //not... String = (FileMode.APPEND);
        var fileStream : FileStream = new FileStream();
        var file:File = File.desktopDirectory.resolvePath("sample.txt");

        fileStream.open (file, fileMode);
        //fileStream.writeMultiByte (text, File.systemCharset); //trying non-English chars??
        fileStream.writeUTFBytes(text); //UTF is Unicode so can handle non-English chars
        fileStream.close();
        //trace("Text Done... check file \"sample.txt\" in Desktop");
    }

} //end Class
} //end Package