1

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

  • 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 Mar 28 '17 at 06:59
  • No, It does n't works if i opened my .exe file using "Run as admin" – Pravin kumar Mar 28 '17 at 08:12
  • update your Air to at least air 3.0, also make sure creating exe with publish button. – payam_sbr Mar 28 '17 at 11:27
  • 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 Mar 28 '17 at 17:18
  • 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 Mar 29 '17 at 05:44
  • Iam using Script: Action script 3.0 and target: AIR sdk 25.0.0.134 for desktop, I have uploaded my *publish settings* snap in the below link 1. [Publish setting link 1](https://drive.google.com/open?id=0B-vA1r4nxL2TSmszYTZlUXdMSTA) 2. [Publish settings link 2](https://drive.google.com/open?id=0B-vA1r4nxL2TVWR6OW9ac1cweWM) – Pravin kumar Mar 29 '17 at 06:00

1 Answers1

1

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
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • PS: The foreign chars showed fine even with basic **Notepad** tool. Let me know if any issues with "gibberish" chars if opened elsewhere. – VC.One Mar 28 '17 at 20:32
  • I have replaced my code with the above one its working fine while debugging and text file was generated with the text ( test Chinese : 你好 世界 ... test Urdu : ہیلو دنیا ... test Russian : Привет мир ) but while publishing to .exe file my window gets closed. while creating a object for SampleClass `var mainReport:SampleClass = new SampleClass();` ; Is there any way to solve this problem ? i have changed my sdk versions and still there is no improvement .The same problem was repeating. – Pravin kumar Mar 29 '17 at 07:01
  • if you remove `mainReport:SampleClass = new SampleClass();` the program is running normally? – Paweł Audionysos Mar 30 '17 at 02:22
  • @pravin I saw you were [making a **projector**](https://drive.google.com/file/d/0B-vA1r4nxL2TVWR6OW9ac1cweWM/view) (an SWF wrapped as EXE file)? To use `FileStream` class you must export a real Windows application (via AIR). If you are not being asked for an _install path_ when you first run the EXE (or your app does not show in Control Panel under _Programs_) then you did it wrong. Didn't have time to update with screen grabs of process but [**this link**](http://www.dummies.com/software/adobe/flash/how-to-publish-an-air-application-in-adobe-flash-cs6/) will help you. – VC.One Mar 30 '17 at 04:36
  • Basically after you selected "Air for Desktop" click the wrench icon next to **Target**. Select "EXE installer" and hit **Publish**. If too much problems about timestamps etc, then choose instead to _Use a certificate_. To create one just click "Create Certificate" button (Flash makes it automatically, but you just give easy testing password to later re-use same certificate file even on other projects.. eg: use p-word: _pravin_ ). Ask anything if my rambling didn't make sense. – VC.One Mar 30 '17 at 04:51
  • Yeah it's working fine thanks a lot Valerio Charles. File was created without any error. – Pravin kumar Mar 30 '17 at 07:16