逐行读取和推送文本文件一行在AS3数组 [英] Reading the text file line by line and push to an array in AS3
本文介绍了逐行读取和推送文本文件一行在AS3数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些code在AS3,将逐行读取文本文件中的行并将其插入到一个数组。这是可能的,而无需任何特殊字符?
I need some code in AS3 that will read a text file line by line and insert it into an array. Is this possible without having any special character?
sample.txt的
sample.txt
Car
van
scooter
bike
我需要阅读的文件,并将其插入到一个数组一样...数组[0] =车,数组[1] =车......
I need to read the file and insert it into an array like...Array[0]=car,Array[1]=car.....
推荐答案
这样的事情可能工作:
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"));
在onLoaded功能的阵列将有你的项目的数组。
The array in the onLoaded function will have your array of items.
编辑 - 为了好玩,我跑了code与样本文件,它的工作就像一个魅力。
Edit- for fun, I ran the code with a sample file and it worked like a charm.
这篇关于逐行读取和推送文本文件一行在AS3数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文