开发者

Read file and put it in to array?

Please help me, I have problem with my program. I'm newbie of flash AS3.0. I want to read filetext (.txt) and put it in to array. here is my sample text from my file.

22 33

开发者_JAVA技巧

11 22

45 56

How can I read file and put it in to array like a[0] = 22 a[1] = 33 a[4]=11 .... or I should use 2 dimension array ? Is flash AS3.0 has 2 dimension array ?

please help me.


import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

var toLoad:URLRequest = new URLRequest("test.txt");
var loader:URLLoader = new URLLoader(toLoad);
loader.addEventListener(Event.COMPLETE, loaded, false, 0, true);

function loaded(evt:Event):void
{
    var txtData:String = evt.currentTarget.data;
    txtData = txtData.replace(/^\s+/, '');
    txtData = txtData.replace(/\s+/g, ' ');
    txtData = txtData.replace(/\s+$/, '')
    var textAr:Array = txtData.split(" ");
    trace(textAr.toString());
}

The RegEx was sourced from Grant Skinner's StringUtils.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜