Skip to main content
Participant
August 25, 2009
Question

xml.onLoad variables undefined outside

  • August 25, 2009
  • 1 reply
  • 605 views

Hi all,

I've been searching this problem for a while and have tried a number of solutions found on google but nothing has worked so far. I'm sure this is a common problem, but due to my lack of flash knowledge I can't logically work through it as I'm used to windows form development, it makes sense to me that the function could access the variables I have defined but they dissapear after the .onLoad event. Does anyone know the common solution to this problem? I want to be able to pass the xml details into the local variables so I can pass on the details into a dynamic text field when movies are hovered over etc.

var myXML:XML = new XML();

myXML.ignoreWhite=true

var nav1TitleText:String;

var nav1Text:String;

var nav2TitleText:String;

var nav2Text:String;

var nav3TitleText:String;

var nav3Text:String;

var nav4TitleText:String;

var nav4Text:String;

myXML.load("navigation.xml");

myXML.onLoad = function(success){

if (success){

nav1TitleText = myXML.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;

trace(nav1TitleText); \\ This one shows the text from the xml file

nav1Text = myXML.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;

nav2TitleText = myXML.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;

nav2Text = myXML.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;

nav3TitleText = myXML.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;

nav3Text = myXML.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue;

nav4TitleText = myXML.firstChild.childNodes[3].childNodes[1].firstChild.nodeValue;

nav4Text = myXML.firstChild.childNodes[3].childNodes[2].firstChild.nodeValue;

}

}

trace(nav1TitleText);  // This one traces undefined

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 25, 2009

your undefined trace() is executing before the defined one.  ie, you're trying to use that variable before it's defined.

correct that and retest.

Participant
August 26, 2009

Hi, thanks for your reply. For some reason I've ended up with two of the same posts.

The other one is here: http://forums.adobe.com/message/2204418#2204418 and has been answered.

Cheers,


Bex

kglad
Community Expert
Community Expert
August 26, 2009

you're welcome.