1

So far this is what I have got:

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

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

enter image description here

Is there any way I could store these values in two different arrays? For example:

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

2 Answers 2

2

Sure. For each entry, you could split by the comma string "," and then append each to it's own array.

This is off the top of my head, so it may need some tweaking:

// 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]);
}
Sign up to request clarification or add additional context in comments.

Comments

0

As i had look around for a while i could not find the appropriate solution so here it is. Hope this help people like me around the globe. I would like to thank mitim for his help.

//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
    }
    */
 }

Hope that helps. Cheers!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.