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


- Joined: Sep 16, 2009
- Posts: 1
- Status: Offline
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):
And here's the (snipped) AS code from the Flash doc.:
I thought declaring:
... 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
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>
<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>
- <?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>
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;
}
}
}
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;
}
}
}
- //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;
- }
- }
- }
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


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
September 16th, 2009, 7:56 am
- ATNO/TW
- Super Moderator


- Joined: May 28, 2003
- Posts: 23404
- Loc: Woodbridge VA
- Status: Offline
I believe you have to do something like this:
http://www.kirupa.com/forum/showthread.php?t=323063
See swooters answer.
http://www.kirupa.com/forum/showthread.php?t=323063
See swooters answer.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 2 posts
- Users browsing this forum: No registered users and 46 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
