2010-09-29 21 views
11

ist es möglich, eine einfache Textdatei mit AS3 oder AIR zu erstellen?AS3/AIR - Erstellen einer einfachen Textdatei?

Beispiel: Ich möchte eine einfache Textdatei namens "MyTextFile.txt" erstellen, lassen Sie es Text enthalten, der lautet: "Dies ist meine Textdatei." und speichern Sie es auf meinem Desktop.

Eine andere Option wäre, die Datei bereits in einem Verzeichnis zu haben, also müsste ich nur den Inhalt neu schreiben - vorausgesetzt, das wäre einfacher.

alles sollte als Hintergrundprozess passieren, ohne dass Dialoge Panel speichern.

Antwort

22
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(); 
3

Ich weiß, dass dies eine alte Post, aber sollten Sie Folgendes beachten eine neue TXT-Datei aus einem Texteingabefeld des Text zu erstellen.

var tf:TextField; 
var fileRef:FileReference; 

function saveFile(evt):void 
{ 
fileRef = new FileReference(); 
fileRef.save(tf.text, "saveFile.txt"); 
} 
0

Auch diesen Text betrachten:

Text fields instead of trace statements

Wenn auf einem mobilen Gerät ausgeführt wird, können Sie die Ausgabe von den Trace-Anweisungen sehen.

Funktion createTracingTextField (x: Zahl, y: Zahl, Breite: Anzahl, Höhe: 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; 

}

und so fort ...

Verwandte Themen