Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-19-2009, 04:28 PM   #1
The King of the World
Join Date: Jul 2008
Location: Dallas, TX
Posts: 34
Angry using XML in other functions

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); }

Last edited by savingedmund; 11-19-2009 at 04:31 PM.
savingedmund is offline   Reply With Quote
Old 11-19-2009, 08:18 PM   #2
Senior Member
Join Date: Sep 2009
Location: Melbourne, Australia
Posts: 1,040

ActionScript Code:
addXMLText(quoteNum, myQuote);

won't work because myQuote is a local variable in showXML

Declare myQuote where you declare quoteNum


ActionScript Code:
var quoteNum:Number = new Number(0); var myQuote:XML;

As far as displaying different quotes based on the button you'll need to do some testing of which button is being rolled over in goQ1


ActionScript Code:
function goQ1 (event:MouseEvent) { switch(event.target) { case button0:     addXMLText(0, myQuote); break; case button1:     addXMLText(1, myQuote); break; } }

(I've no idea what your buttons are called... button0 and button1 are just examples)

Actually as myQuote is scoped by addXMLText there is no real need to pass it just change addXMLText to use my myQuote directly
RogerClark is offline   Reply With Quote
Old 11-19-2009, 08:26 PM   #3
The King of the World
Join Date: Jul 2008
Location: Dallas, TX
Posts: 34

savingedmund is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:16 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.