I’ve been working in Flash using AS2 and loading external XML data into the movie. I am able to load the data into in Flash and parse it, but I haven’t been able to figure out how to load the names of buttons from separate nod values into a textfield.
Unfortunately, I don’t feel I know AS3 well enough and am a little bit rusty on my AS2. Can any one help me figure out what I’m doing wrong?
I created a movie clip which holds the dynamic textfield and placed 30 instances on the stage. Each instance is successively named “cityName*” where i is a number from 1-30. I’ve tried setting the instances as both buttons and movie clips. I also tried setting both the .text and.htmlText attributes, but neither works. I’ve embedded the fonts on the dynamic text field. I’ve also tried changing the field to input instead of dynamic but that doesn’t work either. I’ve been tracing things to try to debug, but haven’t found the issue yet.
Here’s the code:
//load XML data
var citiesData:XML = new XML();
citiesData.ignoreWhite = true;
citiesData.load("30cities.xml");
citiesData.onLoad = parseXMLData;
//define parse function
function parseXMLData(success:Boolean):Void {
//make sure data is loaded and usable
if (success && this.status == 0) {
var theRoot:XMLNode = this.firstChild;
//trace("the root node is called " + theRoot.nodeName);
//trace(" number of child nodes: " + theRoot.childNodes.length);
for (var i:Number = 0; i < theRoot.childNodes.length; i++) {
var theCities:XMLNode = theRoot.childNodes*.firstChild.firstChild;
//trace (" " + theCities.nodeValue);
var city:Array = new Array();
//create array for name
city* = new Object();
city*.cityName = new Array();
//populate with city names
city*.cityName* = theCities.nodeValue;
//SO FAR EVERYTHING TESTED WORKS
//create array for buttons
var buttonLabels:Array = new Array();
for (var b:Number = 0; b < city*.cityName.length; b++) {
buttonLabels.push("cityLabel" + [i + 1] + ".cityName_txt");
//_root[buttonLabels*].htmlText = "Text Here";
}
//populate button text fields with names
buttonLabels*.htmlText = city*.cityName*;
//THIS PART DOESN’T WORK: I CAN’T GET THE NAMES TO FILL THE TEXTBOX INSIDE THE MOVIE CLIP I’M USING AS A BUTTON
}
}
else {
trace("Problem loading XML document");
trace("The status code is: " + this.status);
}
}