Adobe flash cs6 Output window closes automatically while executing Filesteam operation in .exe file but it works fine in flash debug mode

不问归期 提交于 2019-12-11 06:37:02

问题


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:


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


来源:https://stackoverflow.com/questions/43061515/adobe-flash-cs6-output-window-closes-automatically-while-executing-filesteam-ope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!