13

AS3またはAIRでプレーンテキストファイルを作成することは可能ですか?

例:「MyTextFile.txt」という名前のプレーンテキストファイルを作成し、「これは私のテキストファイルです」というテキストを含めるようにします。デスクトップに保存します。

別のオプションは、ファイルをディレクトリにすでに存在させることです。そのため、内容を書き直すだけで済みます。

これらはすべて、保存ダイアログパネルが表示されることなく、バックグラウンドプロセスとして実行される必要があります。

4

3 に答える 3

28
var file:File = File.desktopDirectory.resolvePath("MyTextFile.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("This is my text file.");
stream.close();
于 2010-09-29T15:55:35.427 に答える
3

これが古い投稿であることは知っていますが、入力テキストフィールドのテキストから新しい.txtファイルを作成するには、次のことを考慮してください。

var tf:TextField;
var fileRef:FileReference;

function saveFile(evt):void
{
fileRef = new FileReference();
fileRef.save(tf.text, "saveFile.txt");
}
于 2011-09-06T15:20:42.830 に答える
0

次のテキストも考慮してください。

トレース ステートメントの代わりのテキスト フィールド

モバイル デバイスで実行している場合、トレース ステートメントからの出力は表示されません。

function createTracingTextField(x:Number, y:Number, width:Number, height:Number):TextField {

var tracingTF:TextField = new TextField(); 
tracingTF.x = x; 
tracingTF.y = y; 
tracingTF.width = width; 
tracingTF.height = height; 

// A border lets you more easily see the area the text field covers. 
tracingTF.border = true; 
// Left justifying means that the right side of the text field is automatically 
// resized if a line of text is wider than the width of the text field. 
// The bottom is also automatically resized if the number of lines of text 
// exceed the length of the text field. 
tracingTF.autoSize = TextFieldAutoSize.LEFT; 

// Use a text size that works well on the device. 
var myFormat:TextFormat = new TextFormat(); 
myFormat.size = 18; 
tracingTF.defaultTextFormat = myFormat; 

addChild(tracingTF); 
return tracingTF; 

}

などなど…

于 2014-02-12T15:58:43.697 に答える