Ok, I'm getting more than a little annoyed with this.
I'm loading XML into a file, and then I want to replace the onscreen text with different snippits of text from the XML based upon button clicks.
However, I keep getting an undefined property error every time I try to use the xml in another function other than the load function, because the variable doesn't exist until the load function runs. I get that part.
First, I couldn't pass it to the function that parses the XML and puts the content on the screen (adds the text to the text box and inserts line breaks). So, I added an XML property, so that works finally. However, now I'm passing to a button event. I can't require an XML property there. To get around that, I've tried to encapsualte the XML into every variable type I can think of, and it doesn't work, because it's coersion. It's like a regressive issue now. So I'm screwed? I hope not!
Does that make sense? I need help!!
It's the bottom line of this that gives me the issue: "addXMLText(quoteNum, myQuote);"
ActionScript Code:
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("quote.xml"));
var quoteNum:Number = new Number(0);
function showXML(e:Event):void
{
XML.ignoreWhitespace = true;
var myQuote:XML = new XML(e.target.data);
trace("in the xml");
//trace(myQuote);
addXMLText(quoteNum, myQuote);
}
function addXMLText(currentQuote:int, theXML:XML):void
{
for (var i:Number = 0; i < theXML.quote[currentQuote].p.length(); i++)
{
if (i==0)
{
onStage_txt.text = theXML.quote[currentQuote].p[i];
}
else
{
onStage_txt.appendText(theXML.quote[currentQuote].p[i]);
}
onStage_txt.appendText("\n");
onStage_txt.appendText("\n");
trace("in the loop");
}
}
function goQ1 (event:MouseEvent)
{
quoteNum = 0;
addXMLText(quoteNum, myQuote);
}