3 Replies Latest reply on Oct 24, 2007 7:43 AM by Newsgroup_User

    XML Loading

    phejDC Level 1
      I recently bought Adrian TNT's photo gallery for a project. It was a limited-time project and seemed like the best alternative to writing my own photo gallery on short notice. His photo gallery works by loading an xml file with the same name as the swf from the same directory - the only catch is that the html also needs to live in the same directory.

      What I didn't know while building it was it is not possible on the client's side (due to a proprietary cms) to have the html, xml and swf in the same directory. So now I have to modify the actionscript to load the XML from a specific location.

      Can anyone tell me how to edit the AS attached to pull the xml from /Documents/includes/XML/? I would greatly appriciate it.
        • 1. Re: XML Loading
          Level 7
          phejDC,

          > Can anyone tell me how to edit the AS attached to pull the
          > xml from /Documents/includes/XML/? I would greatly
          > appriciate it.

          Sure thing.

          This if() statement handles the loading.

          if (_parent.xml_file == undefined) {
          my_xml.load((String(_url.slice(0, (_url.length-3))))+"xml");
          } else {
          my_xml.load(img/_parent.xml_file);
          }

          It does the following: If a variable named xml_file is not present
          (that is, has an undefined value) in the parent movie clip, the XML instance
          named my_xml is instructed to load an XML file by the same name as the url
          (the MovieClip._url property) if the SWF. The expression for that -- the
          expression that returns the name of the SWF, but with an .xml extension --
          is this:

          (String(_url.slice(0, (_url.length-3))))+"xml"

          ... so you may precede that with your path:

          "/Documents/includes/XML/" + (String(_url.slice(0, (_url.length-3))))+"xml"

          The other half of that if() statement, the else clause, handles cases in
          which the xml_file variable *is* present. In that case, my_xml is
          instructed to load the XML file specified -- from this location:

          img/_parent.xml_file

          ... so you could replace "img" with your own path:

          "/Documents/includes/XML/" + _parent.xml_file


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."


          • 2. Re: XML Loading
            phejDC Level 1
            Thanks Dave!
            Just to be sure (I'm still trying to learn AS), that new code would look like this, correct? I'm at work so I can't see if that works, but I'll try it home this evening.

            Thanks again!
            • 3. Re: XML Loading
              Level 7
              phejDC,

              > Just to be sure (I'm still trying to learn AS), that new code would
              > look like this, correct?

              That should do it. That would precede the file's name with the path you
              need. To test some of this stuff, I recommend the trace() function, which
              puts values into the Output panel so you can see what's going on under the
              hood ...

              if (_parent.xml_file == undefined) {
              my_xml.load("/Documents/includes/XML/" + (String(_url.slice(0,
              (_url.length-3))))+"xml");
              trace("/Documents/includes/XML/" + (String(_url.slice(0,
              (_url.length-3))))+"xml");
              } else {
              ...

              You can read more about trace() and other debugging techniques for
              ActionScript 2.0 in this article I wrote for the Adobe Dev Center:

              http://www.adobe.com/devnet/flash/articles/debugging_actionscript.html


              David Stiller
              Contributor, How to Cheat in Flash CS3
              http://tinyurl.com/2cp6na
              "Luck is the residue of good design."