vendredi 27 janvier 2017

Actionscript 3: each line from text file as a element in array

So my problem is that trace within the function does trace the first element of the array, but the trace outside if the function does not. I do declare the array variable outside the function, but the data wont save to the array variabel.

var oppgaveLoader:URLLoader = new URLLoader();

oppgaveLoader.load(new URLRequest("oppgaver.txt"));
var oppgaveNr = 0
//store line of text on an array called oppgaver
var oppgaver:Array = []
var oppg:Array = new Array()
oppgaveLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(e:Event){
    oppgaver = e.target.data.split(/\n/)
    trace(oppgaver[0]) //This one traces the frist item in the array
}
trace(oppgaver[0])//This one does not trace the first one in the array

Does anyone know why and/or how to fix it if posible? The file "oppgaver.txt" is located in the same directory as my .fla file

The file "oppgaver.txt" is laid out like this (the text is in norwegian, but each line is going to be a item in the array):

Hvor gjelder forbudsskilt hvis ikke annet er oppgitt?
Hvordan foretar du best mulig bremsing og unnastyring?
Hvordan bør du normalt plassere bilen på en vanlig 2-felst vei?

Aucun commentaire:

Enregistrer un commentaire