6 Replies Latest reply on Jun 18, 2007 6:13 AM by woopig

    xml href question

    woopig
      hello........i have been researching this for a while now and still can't get it to work. does anyone know how to make an <a href> tag work in an xml file? I have a photo gallery flash file that is referencing this xml file:

      </image>

      <image>
      <pic>images/image_2.jpg</pic>
      <thumb>images/thumb_2.jpg</thumb>
      <title>Project 2</title>
      <desc>whatever text</desc>
      </image>

      i tried placing this code <![CDATA[ <a href="www.google.com" target="blank">google</a>]]> in the <desc> tag. it did not work.

      does anyone know what exactly needs to go into the xml file and the flash actionscript to make this work? any help is greatly appreciated. i am at a loss. thanks.
        • 1. Re: xml href question
          Level 7
          This works:

          Assume an instance of TextField named "MyTF";

          var myXml:XML = new XML("<root><![CDATA[<a href=' http://www.adobe.com'
          target='_blank'>CLICK ME</a> ]]></root>")

          MyTF.html=true;
          MyTF.htmlText = myXml.firstChild.firstChild.nodeValue;


          • 2. Re: xml href question
            woopig Level 1
            Raymond...thanks for the reply. I gave it a try and nothing displays in the <desc> tags now. (I am sure I am not doing something right)

            Here is my xml code:

            <image>
            <pic>images/image_1.jpg</pic>
            <thumb>images/thumb_1.jpg</thumb>
            <title>Project 1</title>
            <desc>var myXml:XML = new XML("<root><![CDATA[<a href=' http://www.adobe.com' target='_blank'>CLICK ME</a> ]]></root>")</desc>
            </image>

            And here is the actionscript:

            //XML image gallery
            // To change the images shown within the movie simply
            // change the data.xml file!

            //XML data
            var LoadedFileSize:Number = 0; //Size of loaded data
            var TotalFileSize:Number = 0; //Total file size
            var PercentageFileSize:Number = 0; //Percentage = (Loaded/Total) * 100

            //Movie
            var LoadedMovieSize:Number = 0; //Size of loaded data
            var TotalMovieSize:Number = 0; //Total file size
            var PercentageMovieSize:Number = 0; //Percentage = (Loaded/Total) * 100
            var Percentage:Number = 0;

            //Set the preloader text
            txtLoadText.htmlText = "loading data... " + Percentage + "%"; //Set the preloader text
            //Set the preloader bar size
            mcBar._width = 2*Percentage;

            //Load the XML data
            MyTF.html=true;
            MyTF.htmlText = myXml.firstChild.firstChild.nodeValue;
            xmlData = new XML(); //Create new XML object to load the data into
            xmlData.ignoreWhite = true;
            xmlData.load("data.xml"); //Load the data.xml file. Change path here as needed!
            xmlData.onLoad = loadXML; //After data is loaded call the loadXML() function

            //Function called on XML data load completion
            function loadXML(loaded:Boolean) {
            if (loaded) {
            //Load succesfull
            xmlNode = this;
            } else {
            //Error by loading
            txtLoadText.htmlText = "XML file failed to load!";
            stop();
            }
            }


            What went wrong?

            Thanks, Mark
            • 3. Re: xml href question
              Level 7
              I threw this together and it works. You might want to compare it with your
              code. Few things to note:

              1. txtLoadText.html=true
              2. Assign the listener to the XML object before loading the xml file.
              3. Consider using the more elegant XPathAPI to retrieve nodes.

              data.xml:

              <?xml version="1.0" ?>
              <image>
              <pic>images/image_1.jpg</pic>
              <thumb>images/thumb_1.jpg</thumb>
              <title>Project 1</title>
              <desc><![CDATA[<a href=' http://www.adobe.com' target='_blank'>CLICK
              ME</a> ]]></desc>
              </image>


              // FLA with one instance of TextField named txtLoadText

              // frame 1

              stop();

              //XML data
              var LoadedFileSize:Number = 0; //Size of loaded data
              var TotalFileSize:Number = 0; //Total file size
              var PercentageFileSize:Number = 0; //Percentage = (Loaded/Total) * 100

              //Movie
              var LoadedMovieSize:Number = 0; //Size of loaded data
              var TotalMovieSize:Number = 0; //Total file size
              var PercentageMovieSize:Number = 0; //Percentage = (Loaded/Total) * 100
              var Percentage:Number = 0;

              txtLoadText.html=true;

              //Set the preloader text
              txtLoadText.htmlText = "loading data... " + Percentage + "%";

              var xmlData = new XML();
              xmlData.ignoreWhite = true;
              xmlData.onLoad = loadXML;

              //Function called on XML data load completion
              function loadXML(loaded:Boolean) {
              if (loaded) {
              txtLoadText.htmlText = this.firstChild.childNodes[3].firstChild.nodeValue;

              }
              else {
              txtLoadText.htmlText = "XML file failed to load!";
              }
              }
              xmlData.load("data.xml");


              • 4. Re: xml href question
                Pop_Clingwrap Level 1
                Might also be worth looking in to the asfunction protocol (Flash Help > ActionScript language elements > Global Functions > asfunction protocol)

                This allows you to call AS functions from HTML text and I have used it in the past when retrieving links from XML
                • 5. xml href question
                  woopig Level 1
                  quote:

                  Originally posted by: Newsgroup User
                  I threw this together and it works. You might want to compare it with your
                  code. Few things to note:

                  1. txtLoadText.html=true
                  2. Assign the listener to the XML object before loading the xml file.
                  3. Consider using the more elegant XPathAPI to retrieve nodes.

                  data.xml:

                  <?xml version="1.0" ?>
                  <image>
                  <pic>images/image_1.jpg</pic>
                  <thumb>images/thumb_1.jpg</thumb>
                  <title>Project 1</title>
                  <desc><![CDATA[<a href=' http://www.adobe.com' target='_blank'>CLICK
                  ME</a> ]]></desc>
                  </image>


                  // FLA with one instance of TextField named txtLoadText

                  // frame 1

                  stop();

                  //XML data
                  var LoadedFileSize:Number = 0; //Size of loaded data
                  var TotalFileSize:Number = 0; //Total file size
                  var PercentageFileSize:Number = 0; //Percentage = (Loaded/Total) * 100

                  //Movie
                  var LoadedMovieSize:Number = 0; //Size of loaded data
                  var TotalMovieSize:Number = 0; //Total file size
                  var PercentageMovieSize:Number = 0; //Percentage = (Loaded/Total) * 100
                  var Percentage:Number = 0;

                  txtLoadText.html=true;

                  //Set the preloader text
                  txtLoadText.htmlText = "loading data... " + Percentage + "%";

                  var xmlData = new XML();
                  xmlData.ignoreWhite = true;
                  xmlData.onLoad = loadXML;

                  //Function called on XML data load completion
                  function loadXML(loaded:Boolean) {
                  if (loaded) {
                  txtLoadText.htmlText = this.firstChild.childNodes[3].firstChild.nodeValue;

                  }
                  else {
                  txtLoadText.htmlText = "XML file failed to load!";
                  }
                  }
                  xmlData.load("data.xml");





                  This worked. The link is functioning properly in the <desc> tag but now it does not want to load the thumbs or images?? The <title> does not show up either. Any thoughts?
                  • 6. Re: xml href question
                    woopig Level 1
                    bump*