PDA

View Full Version : [Actionscript 2.0] Codice che non ciene compilato in ordine


ale09hh
25-10-2009, 15:41
Ciao a tutti :D

io ho questo codice

var myXML:XML = new XML();

_global.canzone = new _global.Array();
_global.file = new _global.Array();

myXML.ignoreWhite=true;
myXML.load("playlist.xml");
myXML.onLoad = function(success){

if (success){
var mySong = myXML.firstChild.childNodes;

for(i=0; i<mySong.length; i++){

var songNumber = mySong[i].attributes.number;
var songName = mySong[i].attributes.name;
var songFile = mySong[i].attributes.file;
_global.canzone[i]=songName;
_global.file[i]=songFile;
trace(file[i]);
trace ("My song number "+songNumber+" is titled "+songName+" and its FileName is "+songFile+".")
}


} else {
trace("Error loading playlist.xml");
}

}



trace(file[1]);

che fondamentalmente funziona...

...MA...

... mi esegue per prima l'istruzione che ho scritto per ultima (il trace(file[1]))

ecco l'output:

undefined
music.mp3
My song number 1 is titled Kanye West - Amazing and its FileName is music.mp3.
music2.mp3
My song number 2 is titled Hego - Ridin' and its FileName is music2.mp3.

in pratica è l'undefined all'inizio che da problemi.. Che deriva appunto dal trace() finale...

L'ho scoperto xk togliendolo non esce più undefined...

PERCHE' ME LO ESEGUE ALL'INIZIO???? E' logico che se lo esegue lì l'array non è ancora definito...

E il bello è che se metto il trace() associato ad un bottone (quindi lo eseguo dopo) funziona..

Qualcuno mi può aiutare? GRAZIE!!!:D