6 Replies Latest reply on Dec 12, 2006 5:18 PM by injpix

    Load variables from XML into Flash

    ski_geek Level 1
      I was wondering how to load variables from an XML document to a Flash file? I am familiar with the code to do it for a text file, but was wondering how to do it for XML.

      Many thanks in advance!

      JJ
        • 1. Re: Load variables from XML into Flash
          rohai Level 1
          Hi,

          try to go to this site. It helped me a lot. Hope this helpes.
          • 2. Load variables from XML into Flash
            ski_geek Level 1
            Thanks for the recommendation on the site. What I am trying to do is load varaibles from an XML file into text boxes in my flash movie.

            Here is my loading:
            var my_xml = new XML();
            my_xml.ignoreWhite = true;
            my_xml.onLoad = function(success){
            if (success) {
            gotoAndStop("slide01");
            }
            }
            my_xml.load("narration.xml");

            this is what I have on my frame with the text boxes (the text boxes are also have the variable name in the variable area)
            var narration = my_xml.picture01;
            var my_title = my_xml.my_title;
            var my_date = my_xml.my_date;

            should I do my_date.text = my_xml.my_date; instead?

            my xml doc looks like this

            <?xml version="1.0" encoding="iso-8859-1"?>
            <picture01>This is the text for picture 01</picture01>
            <picture02>This is the text for picture 02</picture02>
            <my_title>Las Vegas</my_title>
            <my_date>October</my_date>

            Any help on this would be GREATLY appreciated!


            Text my_date.text = my_xml.my_date;
            • 3. Re: Load variables from XML into Flash
              injpix Level 3
              To access the value in the “my_title” XML node you need to use the following;
              my_xml.childNodes[2].childNodes[0].nodeValue

              And yes, using the “text” property as you asked in the middle of your post would more ideal.
              • 4. Re: Load variables from XML into Flash
                ski_geek Level 1
                Many thanks. I have the variables loading in properly. One other question:

                Is there any way to call that tag name instead of the child node number?
                So instead of something like this:
                myDate_txt.text = my_xml.firstChild.childNodes[2];

                Can do something like this?
                myDate_txt.text = my_xml.firstChild.myDate;

                Is that possible? I know that does not work the way it is written, but is there code that you can do something like that?
                • 6. Re: Load variables from XML into Flash
                  injpix Level 3
                  Luckly you bumped your post, I must have not noticed you replied with a question.
                  You can obviously have ActionScript look for a node name and do an action when found. For an example the script below will look for a node name of “picture01” and when found it will trace that name and the value in it. This XML is a variation of yours. If you are planning to have multiple nodes in your XML file, then I would structure it likewise. Does this help?