samedi 10 décembre 2016

Read a string in AS3

I have a question regarding to my project which is how to read a string in AS3.

Actually, I have an text file named test.txt. For instance:

It consists of: Sun,Mon,Tue,Wed,Thu,Fri,Sat

and then I want to put all of them into an array and then a string to show them in the dynamic text Box called text_txt:

var myTextLoader:URLLoader = new URLLoader();

myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(e:Event):void
{
 var days:Array = e.target.data.split(/\n/);
 var str:String;
 stage.addEventListener(MouseEvent.CLICK, arrayToString);

 function arrayToString(e:MouseEvent):void
  {
    for (var i=0; i<days.length; i++)
    {
        str = days.join("");
        text_txt.text = str + "\n" + ";"; //it does not work here
    }
 }
}

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

BUT IT DOES NOT show them in different line and then put a ";" at the end of each line !

I can make it to show them in different line, but I need to put them in different line in txt file and also I still do not get the ";" at the end of each line unless put it in the next file also at the end of each line.

And then I want to read the string and show an object from my library based on each word or line. for example:

//I  do not know how to write it or do we have a function to read a string and devide it to the words after each space or line 
if (str.string="sun"){
 show(obj01);
}
if (str.string="mon"){
 show(obj02);
}

I hope I can get the answer for this question. Please inform me if you can not get the concept of the last part. I will try to explain it more until you can help me. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire