I’m starting to learn XML with Flash–the Kirupa tutorial on XML as well as Lee Brimelow’s XML tutorials on gotoAndLearn() have been wonderful. But here’s an actionscript challenge: I’m trying to create a list of links, with the link text and url of each link stored in an XML file. The file looks like this:
<?xml version="1.0"?>
<myMenu>
<myEssay name="Why No One's a Fan of Stanley Fish (2006)" url="docs/stanfish.html" />
<myEssay name="The Fiction of History (2006)" url="docs/hwhite.html" />
...
</myMenu>
I’ve seen projects that load each link into a textbox in an iteration of a premade movieclip and set an onRelease event to the whole movieclip to open the link. This is a novel solution, but won’t work for me for two reasons: 1.) I have about forty links and a series of forty movieclips, even if they’re only 20 pixels tall, will run off the stage, and 2.) I don’t yet know how to make a scrollbar for a series of movieclip symbols.
But I do know how to make a scrollbar for a dynamix textfield, so that’s what I’m doing. This AS loads in the names of my essays and displays them, one on each line, in a dynamic textbox called essayLinks:
menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function(success) {
if (success) {
myEssays = this.firstChild.childNodes;
for (var i=0; i<myEssays.length; i++) {
essayLinks.text += (myEssays*.attributes.name + "
");
}
}
}
The problem is how to attach a hyperlink (destination stored in the XML as an attribute called “url”) to each line. I immediately looked to the TextFormat class (with its TextFormat.url and TextFormat.target properties), but I think that has to be applied to a whole textfield, and not just a string of text (If I could I would store **myEssays.attributes.name *as a temporary string variable and apply the TextFormat to it). So this is where things fall apart. Tell me if I’m going about this all wrong, but if I’m not I would really like some help.
Cheers,
Steve