2 Replies Latest reply on Jan 23, 2008 2:30 PM by debriscreator

    XML and Flash

    debriscreator
      I'm having trouble creating a button in a flash movie that pulls a URL from an xml file.

      Here is my Action Script (bold text is what i'm having trouble with)
      ----------------------------------------------------------------
      stop();
      var nInterval = setInterval(Play, 9000);
      function Play() {
      clearInterval(nInterval);
      gotoAndPlay(_currentframe+1);
      }
      myXML = new XML()
      myXML.ignoreWhite = true
      myXML.load("ascolta.xml")
      myXML.ref = this
      myXML.onLoad = function(succes){
      if(succes){

      var root = this.firstChild
      nodes = root.childNodes
      for(var i=0; i<nodes.length; i++) {
      this.ref["Title_txt"+i].text = nodes .attributes.name
      subnodes = nodes
      .childNodes
      this.ref["heading"+i].text = subnodes[0].firstChild.toString()
      this.ref["URL"+i].text = subnodes[1].firstChild.toString()
      _root.yo = this.ref["URL"+i].text

      this.ref["article"+i].text = subnodes[2].firstChild.toString()

      }
      } else trace("Error loading XML document")
      }
      ---------------------------------------------------------------------

      below is my button code

      ---------------------------------------------------------------------
      on (release) { getURL(_root.yo); }

      ---------------------------------------------------------------------

      below is my xml file

      ---------------------------------------------------------------------

      <?xml version="1.0" ?>
      - <Widget>
      - <menu1 name="Menu Name 1">
      <Heading1>Heading 1</Heading1>

      <URL1>www.link1.com</URL1>

      <Article1>Article 1</Article1>

      </menu1>


      - <menu2 name="Menu Name 2">
      <Heading2>Heading 2</Heading2>

      <URL2>www.link2.com</URL2>

      <Article2>Article 2</Article2>

      </menu2>


      - <menu3 name="Menu Name 3">
      <Heading3>Heading 3</Heading3>

      <URL3>www.link3.com</URL3>

      <Article3>Article 3</Article3>

      </menu3>


      - <menu4 name="Menu Name 4">
      <Heading4>Heading 4</Heading4>

      <URL4>www.link4.com</URL4>

      <Article4>Article 4</Article4>

      </menu4>




      <Widget>
      ---------------------------------------------------------------------
      does anyone know why my button pulls an undefined link?

      thanks in advance - dave
        • 1. Re: XML and Flash
          Level 7
          Hi debriscreator,

          Maybe you forgot to post something but "getURL" loads a URL into the
          current browser window (like a regular HTTP request). It's not used to load
          XML data. If an attempt to load your XML document is being made, it's a
          coincidence. To verify what's going on, grab yourself a web debugging proxy
          like Fiddler or Charles. Charles is commercial but *much* better for Flash.
          In any event, both should do for this. Run the program and then run your
          code. Watch the requests being made by your computer. Is your code
          requesting a URL or the XML document? If the XML request is being sent,
          what's the return error code? It should be 200. If it's a 404 (not found),
          it means that the XML document is not where you think it should be. Have a
          look at the full URL path (you can usually right-click and copy the full
          path), paste it into a browser and try to load it there. It is very likely
          it's not where you think it is. Finally, it may be a security error
          (crossdomain or something similar). Check to see if a request is being made
          for a crossdomain.xml file...this usually indicates that Flash is looking
          for one and if it doesn't find it, your request will be cancelled.

          Hope this helps.

          Regards,
          Patrick Bay
          BAY NEW MEDIA


          "debriscreator" <webforumsuser@macromedia.com> wrote in message
          news:fn87mg$1fb$1@forums.macromedia.com...
          > I'm having trouble creating a button in a flash movie that pulls a URL
          > from an
          > xml file.
          >
          > Here is my Action Script (bold text is what i'm having trouble with)
          > ----------------------------------------------------------------
          > stop();
          > var nInterval = setInterval(Play, 9000);
          > function Play() {
          > clearInterval(nInterval);
          > gotoAndPlay(_currentframe+1);
          > }
          > myXML = new XML()
          > myXML.ignoreWhite = true
          > myXML.load("ascolta.xml")
          > myXML.ref = this
          > myXML.onLoad = function(succes){
          > if(succes){
          >
          > var root = this.firstChild
          > nodes = root.childNodes
          > for(var i=0; i<nodes.length; i++) {
          > this.ref["Title_txt"+i].text = nodes .attributes.name
          > subnodes = nodes
          .childNodes
          > this.ref["heading"+i].text = subnodes[0].firstChild.toString()
          > this.ref["URL"+i].text = subnodes[1].firstChild.toString()
          > _root.yo = this.ref["URL"+i].text

          > this.ref["article"+i].text = subnodes[2].firstChild.toString()
          >
          > }
          > } else trace("Error loading XML document")
          > }
          > ---------------------------------------------------------------------
          >
          > below is my button code
          >
          > ---------------------------------------------------------------------
          > on (release) { getURL(_root.yo); }
          >
          > ---------------------------------------------------------------------
          >
          > below is my xml file
          >
          > ---------------------------------------------------------------------
          >
          > <?xml version="1.0" ?>
          > - <Widget>
          > - <menu1 name="Menu Name 1">
          > <Heading1>Heading 1</Heading1>
          >
          > <URL1>www.link1.com</URL1>
          >
          > <Article1>Article 1</Article1>
          >
          > </menu1>
          >
          >
          > - <menu2 name="Menu Name 2">
          > <Heading2>Heading 2</Heading2>
          >
          > <URL2>www.link2.com</URL2>
          >
          > <Article2>Article 2</Article2>
          >
          > </menu2>
          >
          >
          > - <menu3 name="Menu Name 3">
          > <Heading3>Heading 3</Heading3>
          >
          > <URL3>www.link3.com</URL3>
          >
          > <Article3>Article 3</Article3>
          >
          > </menu3>
          >
          >
          > - <menu4 name="Menu Name 4">
          > <Heading4>Heading 4</Heading4>
          >
          > <URL4>www.link4.com</URL4>
          >
          > <Article4>Article 4</Article4>
          >
          > </menu4>
          >
          >
          >
          >
          > <Widget>
          > ---------------------------------------------------------------------
          > does anyone know why my button pulls an undefined link?
          >
          > thanks in advance - dave
          >

          • 2. Re: XML and Flash
            debriscreator Level 1
            Hi Thanks for responding

            I installed charles but can't seem to get it working. Nothing shows up in the structure or sequence tab. Maybe i don't have java installed? Not sure... anyway.. i think i know what you are saying but what i tried to do was turn the xml string loaded with

            this.ref["URL"+i].text = subnodes[1].firstChild.toString()

            into a variable like this

            _root.yo = this.ref["URL"+i].text

            then in the button i tried to use geturl to open a link using the variable i created

            on (release) { getURL(_root.yo); }

            what am i doing wrong here? so confused - dave