Pregunta

Es posible crear un archivo de texto con AS3 o AIR?

ejemplo: me gustaría crear un archivo de texto plano llamado "MyTextFile.txt", tienen que contiene el texto que dice "Este es mi archivo de texto." y guardarlo en el escritorio.

Otra opción sería tener el archivo ya existe en un directorio, por lo que sólo tendría que volver a escribir su contenido -. Asumiendo que sería más fácil

todo lo cual debe ocurrir como un proceso en segundo plano, sin ningún tipo de ahorro dialoge panel que aparecen.

¿Fue útil?

Solución

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

Otros consejos

Sé que esto es una entrada antigua, pero tenga en cuenta lo siguiente para crear un nuevo archivo .txt del texto de un campo de texto.

var tf:TextField;
var fileRef:FileReference;

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

Ten en cuenta también este texto:

Los campos de texto en lugar de instrucciones de seguimiento

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

Función createTracingTextField (x:, y: número,                                 anchura: Número, altura: 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 ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top