I hate doing this, but am not sure what else to do at the moment. The following code is supposed to read the label and url from an xml file and put that info into dynamically-created text boxes on the stage that the user can click on to navigate a website:
#include "mc_tween2.as"
var fontAssign:TextFormat = new TextFormat();
fontAssign.font = "shFont_Verd";
XML.prototype.ignoreWhite = true; // ignores white space for all XML
var myXML:XML = new XML();
var myInfo = myXML.firstChild.childNodes; //references <info
myXML.onLoad = function(success):Void{
if(success){
var child = myXML.firstChild;
var myLength = child.childNodes.length;
for(i=0; i < myLength; i++){
currInfo = child.childNodes*;
var gap:Number = 740/myLength * i; // evenly spaces out each button based on how many there are and the width of the stage
trace(gap);
/*---------- < CREATE TEXT BOXES > ----------- */
// Format text and ASSIGN URL
var fontAssign:TextFormat = new TextFormat();
with(fontAssign){
font = "Sh_Verd";
url = currInfo.attributes.url; //this, combined with html=true in footerText allows for the text to become a link AS Bible P460
underline = true;
size = 12;
} // inst name, depth, x, y, width, height
this.createTextField("footerText_"+i, i, gap, 30, 0, 0);
with (footerText_+i){
text = currInfo.attributes.label;
autoSize = "center";
selectable = false;
embedFonts = true;
antiAliasType = "advanced";
gridFitType = "subpixel";
//textColor = 0xE6F2FF;
textColor = 0xF89532;
onRollOver = function():Void{
//[color, alpha, blurRadius, strength, quality, inner, knockout, seconds, animation type, delay,
glowTo(0xFFFFFF, 90, 2, 125, 2, false, false, 0, "linear", 0) // strength 125
}
onRollOut = function():Void{
glowTo(0xFFFFFF, 90, 2, 0, 2, false, false, 0, "linear", 0) // strength 0
}
html = true; // enables the HTML function provided by the TextFormat object
setTextFormat(fontAssign);
trace(text);
}
}
} else {
trace("XML failed to load");
}
}
myXML.load("buttonInfo.xml");
Here is the XML doc:
<?xml version="1.0"?>
<!DOCTYPE buttonInfo[
<!ELEMENT buttonInfo (info)>
<!ELEMENT info (label, url)>
<!ELEMENT label (#PCDATA)>
<!ELEMENT url (#PCDATA)>
]>
<buttonInfo>
<info label= "About Us" url="aboutUs.html" />
<info label= "Services" url="services.html" />
<info label= "News Room" url="newsRoom.html" />
<info label= "Contact US" url="contactUs.html" />
<info label= "Get Creative!" url="getCreative.html" />
</buttonInfo>
I’m ***trying ***to design more dynamic code!!! Is this dynamic enough? :cross-eye If any of you could scan the AS and tell me why nothing appears on the stage, I’d be really grateful. Thanks!