1

到目前为止,这就是我所得到的:

var  myLoader:URLLoader  =  new  URLLoader(new  URLRequest("myTxtFile.txt"));
myLoader.addEventListener(Event.COMPLETE,  loadComplete);

function  loadComplete(e:Event):void
{
   trace(myLoader.data);    
 }

在此处输入图像描述

有什么办法可以将这些值存储在两个不同的数组中?例如:

 myarray[0] = word1
 myarrayOne[0] = hint
4

2 回答 2

2

当然。对于每个条目,您可以用逗号字符串“,”分割,然后将每个条目附加到它自己的数组中。

这不在我的脑海中,所以它可能需要一些调整:

// split the data by new lines, to end up with an array of entries
var entries:Array = myLoader.data.split("\n\r");

var myarray:Array = new Array();
var myarrayOne:Array = new Array();

// for each entry in the array, split by the comma and append to the desired arrays
var temp:Array;
for(var entry:String in entries){
    temp = entries[entry].split(",");
    myarray.push(temp[0]);
    myarrayOne.push(temp[1]);
}
于 2013-09-25T04:46:32.640 回答
0

当我环顾四周时,我找不到合适的解决方案,所以就在这里。希望这可以帮助全球像我这样的人。我要感谢mitim的帮助。

//create a new URL Loader
 var myLoader:URLLoader = new URLLoader();

//get file replace yourFileName.txt with fileName you want to read
 myLoader.load(new URLRequest("yourTxtFileName.txt"));

//store line of text on an array called lineOfText
 var lineOfText:Array = new Array;

//declare array to save word
 var textOne:Array = new Array;
 var textTwo:Array = new Array;

//set actionEvent 
 myLoader.addEventListener(Event.COMPLETE, onLoaded);

//create a function called onLoaded
 function onLoaded(e:Event):void {

//get a single line and store in array called lineOfText 
 lineOfText = e.target.data.split(/\n/);

 //create a new tempArray
var temp:Array;

    //use for loop to add words to array 

    for(var entry:String in lineOfText) {
        //store the lineofText[] and split the word if comma is found
        temp = lineOfText[entry].split(",");

        //add the word to an array now
        textOne.push(temp[0]);
        texttwo.push(temp[1]);

    }//end for

    /*
    //this is for checking purpose 
    for(var check:String in words) {

        trace(textOne[check]);//trace words array
        trace(textTwo[check]);//trace hints array
    }
    */
 }

希望有帮助。干杯!!

于 2013-09-25T09:47:11.340 回答