vin*_*eth 10 flash actionscript-3
我需要AS3中的一些代码,它们将逐行读取文本文件并将其插入到数组中.这可能没有任何特殊性质吗?
为sample.txt
car
van
scooter
bike
Run Code Online (Sandbox Code Playgroud)
我需要读取文件并将其插入到数组中,如:
Array[0]=car
Array[1]=van
Array[2]=scooter
Array[3]=bike
Run Code Online (Sandbox Code Playgroud)
Kek*_*koa 27
这样的事情可能有用:
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
var myArrayOfLines:Array = e.target.data.split(/\n/);
}
myTextLoader.load(new URLRequest("myText.txt"));
Run Code Online (Sandbox Code Playgroud)
onLoaded函数中的数组将包含您的项目数组.
编辑 - 为了好玩,我用一个示例文件运行代码,它就像一个魅力.
以下是使用ActionScript 3加载和读取不同文件类型的示例:
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
var fileStream:FileStream = new FileStream(); // Create our file stream
fileStream.open(myFile, FileMode.READ);
var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable); // Read the contens of the
fileContents_txt.text = fileContents; // Display the contents. I've created a TextArea on the stage for display
fileStream.close(); // Clean up and close the file stream
Run Code Online (Sandbox Code Playgroud)
读取字符串后,可以使用int.valueOf()将字符串转换为整数.
| 归档时间: |
|
| 查看次数: |
54066 次 |
| 最近记录: |