Trying to get URL from XML into SWF as a clickable link

  • joerugg
  • Born
  • Born
  • joerugg
  • Posts: 1

Post 3+ Months Ago

Hey all ...

My first post here, so please, be nice!

I've been building a map in flash which gets most of its info from an XML file. All seems to work fine with the exception of URLs linking to other pages on our site.

The idea is user clicks a town on the map, info on that town appears in a common info box within the SWF -- this info includes link to that town's page. Everything passes from the XML to the SWF correctly, with the exception of the links/URLs.

Here's a sample of my XML Code, which is being loaded into my .swf (URLs were stripped out by the forum software, but it's obvious where they go):

XML Code: [ Select ]
<?xml version="1.0" encoding="utf-8"?>
 
<site>
   <pages>
 
      <page page_number="1">
         <town>NEW LONDON</town>
         <title>New London Headline Goes Here</title>
         <date>Date Goes Here ...</date>
         <content>Short abstract of town here ...</content>
         <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
         <image>zip06logo.png</image>
      </page>
 
      <page page_number="2">
         <town>NORTH STONINGTON</town>
         <title>North Stonington Headline Goes Here</title>
         <date>Date Goes Here ...</date>
         <content>Short abstract of town here ...</content>
         <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
         <image>zip06logo.png</image>
      </page>
   </pages>
 
</site>
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <site>
  4.    <pages>
  5.  
  6.       <page page_number="1">
  7.          <town>NEW LONDON</town>
  8.          <title>New London Headline Goes Here</title>
  9.          <date>Date Goes Here ...</date>
  10.          <content>Short abstract of town here ...</content>
  11.          <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
  12.          <image>zip06logo.png</image>
  13.       </page>
  14.  
  15.       <page page_number="2">
  16.          <town>NORTH STONINGTON</town>
  17.          <title>North Stonington Headline Goes Here</title>
  18.          <date>Date Goes Here ...</date>
  19.          <content>Short abstract of town here ...</content>
  20.          <link><a href='URL GOES HERE'>VISIT TOWN PAGE</a></link>
  21.          <image>zip06logo.png</image>
  22.       </page>
  23.    </pages>
  24.  
  25. </site>


And here's the (snipped) AS code from the Flash doc.:

ACTIONSCRIPT Code: [ Select ]
//Create a holder that will contain the title, content and image.
var holder:MovieClip = new MovieClip();
holder.addChild(townText);
holder.addChild(titleText);
holder.addChild(dateText);
holder.addChild(contentText);
holder.addChild(linkText);
 
//Add the holder to the stage
addChild(holder);
 
//Hide the holder at the beginning of the movie.
//We don't want to show any content before the title, content and image has
//been loaded.
holder.visible = false;
 
// BUTTON CODE HERE
 
// END BUTTON CODE
 
//Specify the path to the XML file.
//You can use my path or your own.
var xmlFilePath:String = "test.xml";
 
// LOAD XML
 
//We save the loaded XML data into a variable
var XMLData:XML;
 
//Load the XML file.
//We call the xmlDataLoaded() function when the loading is complete.
var loader = new URLLoader();
loader.load(new URLRequest(xmlFilePath));
loader.addEventListener(Event.COMPLETE, xmlDataLoaded);
 
//This function is called when the XML file is loaded
function xmlDataLoaded(e:Event):void {
 
   //Create a new XML object from the loaded XML data
   XMLData = new XML(loader.data);
   XMLData.ignoreWhitespace = true;
 
   //Call the function that adds event listeners for the buttons
   addEventListeners();
 
   // EVENT LISTENERS FOR BUTTONS ALL 38 OF 'EM - CODE SNIPPED
 
   //Loop through the pages found in the XML file
   for each (var page:XML in XMLData.pages.page) {
 
      //Check if the page number that we're looking is found from the XML data.
      //The "page.@page_number" refers to the page's "page_number" attribute in the XML file.
      if (page. @ page_number == pageNumber) {
 
         //Set the title from the XML
         titleText.text = page.title;
 
         //Set the town from the XML
         townText.text = page.town;
 
         //Set the title from the XML
         dateText.text = page.date;
         linkText.htmlText = page.link;
         contentText.text = page.content;
 
         
         //Load the image (the image path is specified in the XML)
         var imageLoader = new Loader();
         imageLoader.load(new URLRequest(page.image));
 
         //Listen when the image is loaded
         imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
 
         //We can exit the loop now
         break;
      }
   }
}
  1. //Create a holder that will contain the title, content and image.
  2. var holder:MovieClip = new MovieClip();
  3. holder.addChild(townText);
  4. holder.addChild(titleText);
  5. holder.addChild(dateText);
  6. holder.addChild(contentText);
  7. holder.addChild(linkText);
  8.  
  9. //Add the holder to the stage
  10. addChild(holder);
  11.  
  12. //Hide the holder at the beginning of the movie.
  13. //We don't want to show any content before the title, content and image has
  14. //been loaded.
  15. holder.visible = false;
  16.  
  17. // BUTTON CODE HERE
  18.  
  19. // END BUTTON CODE
  20.  
  21. //Specify the path to the XML file.
  22. //You can use my path or your own.
  23. var xmlFilePath:String = "test.xml";
  24.  
  25. // LOAD XML
  26.  
  27. //We save the loaded XML data into a variable
  28. var XMLData:XML;
  29.  
  30. //Load the XML file.
  31. //We call the xmlDataLoaded() function when the loading is complete.
  32. var loader = new URLLoader();
  33. loader.load(new URLRequest(xmlFilePath));
  34. loader.addEventListener(Event.COMPLETE, xmlDataLoaded);
  35.  
  36. //This function is called when the XML file is loaded
  37. function xmlDataLoaded(e:Event):void {
  38.  
  39.    //Create a new XML object from the loaded XML data
  40.    XMLData = new XML(loader.data);
  41.    XMLData.ignoreWhitespace = true;
  42.  
  43.    //Call the function that adds event listeners for the buttons
  44.    addEventListeners();
  45.  
  46.    // EVENT LISTENERS FOR BUTTONS ALL 38 OF 'EM - CODE SNIPPED
  47.  
  48.    //Loop through the pages found in the XML file
  49.    for each (var page:XML in XMLData.pages.page) {
  50.  
  51.       //Check if the page number that we're looking is found from the XML data.
  52.       //The "page.@page_number" refers to the page's "page_number" attribute in the XML file.
  53.       if (page. @ page_number == pageNumber) {
  54.  
  55.          //Set the title from the XML
  56.          titleText.text = page.title;
  57.  
  58.          //Set the town from the XML
  59.          townText.text = page.town;
  60.  
  61.          //Set the title from the XML
  62.          dateText.text = page.date;
  63.          linkText.htmlText = page.link;
  64.          contentText.text = page.content;
  65.  
  66.          
  67.          //Load the image (the image path is specified in the XML)
  68.          var imageLoader = new Loader();
  69.          imageLoader.load(new URLRequest(page.image));
  70.  
  71.          //Listen when the image is loaded
  72.          imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
  73.  
  74.          //We can exit the loop now
  75.          break;
  76.       }
  77.    }
  78. }


I thought declaring:

ACTIONSCRIPT Code: [ Select ]
linkText.htmlText = page.link;


... would be sufficient, but apparently not. The URL shows up but is not a clickable link. (I've also set the dynamic text box for linkText to be HTML).

Can't figure out what I'm doing wrong here ....

Thanks for any help you can give.

= jr
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

I believe you have to do something like this:
http://www.kirupa.com/forum/showthread.php?t=323063

See swooters answer.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.