Hi I am pulling in some lyrics from an xml file, and Im wanting to store them in an array, so I can access them from time to time, after the initial xml code has been fired.
var lyrics:Array = new Array();
var lyricNum:Number;
function getLyrics(xmlData)
{
xmlNode = xmlData.firstChild.childNodes;
lyricNum = xmlNode.length;
lyric = *;
for(i=0;i<lyricNum;i++)
{
lyric* = xmlNode*.attributes.lyric;
lyrics* = lyric*;
trace(lyrics); //this Does trace the contents of the array
}
}
trace(lyrics);//this won't pick up the array - Why when I have placed my variable outside of the for loop in the root code!?
I have laid my case in the code where the traces reside. Can anyone help why I cant access the array after the for loop has been processed - it says it is undefined.
!!Thanks!!
you have to declare the arrays before the for loop
myArray =[]
Well, the thing is…Inside the function it does trace, but the function is executed in the main timeline, “slower”, if you will, than the trace command.
So, when you trace for the array in _root, it returns nothing because it hasn’t been populated yet.
I’d try something like:
ActionScript Code:
[LEFT][COLOR=#808080]*//after the function*[/COLOR]
[COLOR=#0000ff]onEnterFrame[/COLOR] = [COLOR=#000000]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]//[/COLOR]
[COLOR=#0000ff]if[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]trace[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000ff]delete[/COLOR] [COLOR=#0000ff]onEnterFrame[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]
I haven’t actually tried this, but it might work.
Thanks … myArray =[] I thought is achieving the same as lyrics* = lyric*;
Ok mastermode - I get you … I think therefore - I fire my ‘trace’ from another function - after the code has been digested from initiation …/ /
Remember that Flash does background loading - i.e. the XML file won’t be loaded until the onLoad event is fired from the XML loader object.
Also some of your syntax is a bit … odd?