Flash man by Zerofractal Studio
One of my first assignments here at The Roanoke Times was to create a package detailing Virginia Tech’s 2007 football season, with links to archival stories, photo galleries and videos. I knew I wanted to use XML, but I wasn’t sure how to put a URL link in XML and have it show up as a link in Flash. Why I bring this up is because a recent assignment made me go back to these files to familiarize myself with the code, so I wanted to share it with you all in case you ever get stumped.
I have to give credit to former AJC coworker Bryan Perry (now design director at CNN.com) for pointing me in the right direction. You can download his example files HERE. These files are great because they are as basic as you can get … allowing for a quick learning curve. His XML file uses attributes, but it also works for child nodes. Once you understand how it works, you can customize it and add as many HTML links as necessary.
Here’s how it works:
For the XML, it can be pretty basic: (style and carrots are missing so the code will show up … download the files to see it all)
parentnode
thecontent:http://www.innovativeinteractivity.com
parentnode
Once you have your XML file, create a dynamic text field on your stage, give it an instance name (in the following example it is “mycontent”), and click “Render text as HTML” (the <> symbol). Then, in your Actions panel, write the following code (AS2):
function loadXML(loaded) {
if (loaded) {
xmlNode = this.childNodes[0];
thiscontent = xmlNode.firstChild.firstChild; /*this will change depending on how you write your XML*/
trace(thiscontent);
_root.mycontent.html = true; /*this is the instance name of your text field. Make sure it is set to true*/
_root.mycontent.htmlText = “This is a cool site!” ; /*This is basic HTML structure, so simply change out the text to what you want it to say, and it will link to whatever URL you set in your XML*/
}
}
xmlData = new XML();
xmlData.onLoad = loadXML;
xmlData.ignoreWhite = true;
xmlData.load(“test.xml”); /*set it to the name of your XML file */
(Thanks Bryan!)
This is interesting. In AS3, the XML follows E4X standards, thus making it easier to handle XML.
By the way, when you come back to NC, make sure to say hi
to the people at school if you see them.
Nice blog!