逐行读取文本文件并推送到AS3中的数组 [英] Reading the text file line by line and push to an array in AS3

查看:27
本文介绍了逐行读取文本文件并推送到AS3中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些 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

    car
    van
    scooter
    bike

我需要读取文件并将其插入到如下数组中:

I need to read the file and insert it into an array like:

Array[0]=car
Array[1]=van
Array[2]=scooter
Array[3]=bike

推荐答案

这样的事情可能会奏效:

Something like this may work:

var myTextLoader:URLLoader = new URLLoader();

myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(e:Event):void {
    var myArrayOfLines:Array = e.target.data.split(/
/);
}

myTextLoader.load(new URLRequest("myText.txt"));

onLoaded 函数中的数组将包含您的项目数组.

The array in the onLoaded function will have your array of items.

编辑 - 为了好玩,我用一个示例文件运行了代码,它的效果非常好.

Edit- for fun, I ran the code with a sample file and it worked like a charm.

这篇关于逐行读取文本文件并推送到AS3中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆