2010-09-29 41 views
11

¿es posible crear un archivo de texto plano con AS3 o AIR?AS3/AIR - ¿Crear un archivo de texto sin formato?

ejemplo: me gustaría crear un archivo de texto sin formato llamado "MyTextFile.txt", hacer que contenga texto que diga "Este es mi archivo de texto". y guárdalo en mi escritorio.

otra opción sería tener el archivo ya existente en un directorio, por lo que solo tendría que volver a escribir su contenido, suponiendo que sería más fácil.

todo lo cual debería pasar como un proceso en segundo plano, sin que aparezca ningún panel de salvar dialogo.

Respuesta

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

Sé que esta es una publicación anterior, pero considere lo siguiente para crear un nuevo archivo .txt a partir del texto de un campo de texto de entrada.

var tf:TextField; 
var fileRef:FileReference; 

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

Ten en cuenta también este texto:

Text fields instead of trace statements

Cuando se ejecuta en un dispositivo móvil, no se puede ver el resultado de las instrucciones de seguimiento.

función createTracingTextField (x:, y: Number, width:, 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; 

}

Y así sucesivamente ...

Cuestiones relacionadas