1 Reply Latest reply on Dec 6, 2012 6:50 PM by Ned Murphy

    importing images XML Problem

    TheScarecrow Level 1

      Hey I have an XML file that has images in it.  I am wanting to import the images into flash into arrays then I want place them on the stage. I have it importing corretly I think.  Has anyone done this before and give me any hints at placing the images?  I figure I will have to set a variable to too the function what array to use.  Thanks.

       

      XML CODE

      <gallery>

                <image id="image01" category = "Registration" url="DSCN2217.JPG" />

                <image id="image02" category = "Registration" url="DSCN2218.JPG" />

                <image id="image03" category = "Registration" url="DSCN2219.JPG" />

                <image id="image04" category = "Registration" url="DSCN2220.JPG" />

                <image id="image05" category = "Registration" url="DSCN2221.JPG" />

       

                <image id="image01" category = "Banquet" url="DSCN2222.JPG" />

                <image id="image02" category = "Banquet" url="DSCN2223.JPG" />

                <image id="image03" category = "Banquet" url="DSCN2224.JPG" />

                <image id="image04" category = "Banquet" url="DSCN2225.JPG" />

                <image id="image05" category = "Banquet" url="DSCN2226.JPG" />

      </gallery>

       

      AS3 SCRIPT

      xmlData = new XML();

      xmlData.ignoreWhite = true;

      xmlData.load("images.xml");

      //xmlData.onLoad =loadXML;

      xmlData.onLoad = function(success:Boolean)

      {

                if (success)

                {

                          if (xmlData.status == 0)

                          {

                                    regArray = new Array();

                                    banArray = new Array();

                                    var xmlDataToXMLString:String = new String();// initializes a new string variable

                                    xmlDataToXMLString = xmlData.toString();// converts dots XML object to a string and stores it in dotsToXMLString.

       

       

                                    var xmlDataXML:XML = new XML(xmlDatadotsToXMLString);// creates new XML object with the string contents from above.

                                    xmlDataXML.parseXML(xmlDataToXMLString);// parses the string from above.

       

       

                                    var xmlDataNodes:Object = xmlDataXML.firstChild;// Saves the firstChild (in this case, the outermost element) as an object

                                    var xmlDataNodesChildren:Object = xmlDataNodes.childNodes;// Saves the childNodes of firstChild as an object

                                    for (i = 0; i < xmlDataNodesChildren.length; i++)

                                    {

                                              switch (xmlDataNodes.childNodes[i].attributes.category)

                                              {

                                                        case "Registration" :

                                                                  xmlNodeID = xmlDataNodes.childNodes[i].attributes.ID;

                                                                  xmlNodeURL = xmlDataNodes.childNodes[i].attributes.url;

                                                                  //regArray = new Array();

                                                                  regArray.push({id:xmlNodeID, url:xmlNodeURL});

                                                                  //trace(xmlDataNodes.childNodes[i]);

                                                                  break;

                                                        case "Banquet" :

                                                                  xmlNodeID = xmlDataNodes.childNodes[i].attributes.ID;

                                                                  xmlNodeURL = xmlDataNodes.childNodes[i].attributes.url;

                                                                  //regArray = new Array();

                                                                  banArray.push({id:xmlNodeID, url:xmlNodeURL});

                                                                  break;

                                              }

                                              //trace(xmlDataNodes.childNodes[i].attributes.category);

       

       

                                    }

                                    trace(regArray);

                                    trace(banArray);

                          }

                          else

                          {

                                    trace("Problem parsing XML.");

                          }

                }

                else

                {

                          trace("Could not load XML");

                }

      }

       

       

      function placeImages() {

       

      }