Question
Creating Dynamic Text Fields
Hey there,
I'm reading in an XML file, and then want to be able to create a list of song names.
I'm using a function to loop through the XML file and create a text field for each entry.
Here's my function:
function createMenu(xmlFile,medType,medCat) {
var items = xmlFile.firstChild.childNodes; // xml file -> music -> songs array
var count = 0;
var spacing = 20;
for(i=0;i<items.length;i++) {
if(items .nodeName == medType) {
if(items.attributes.category == medCat) {
var sTitle = items .firstChild.firstChild;
var path = items.childNodes[1].firstChild;
var songName:String = "songName"+i;
var t:TextFormat = new TextFormat();
t.color = 0xFFFFFF;
t.size = 12;
t.font = "BitStream Vera Sans";
this.createTextField(songName,this.getNextHighestDepth(),292,100,300,200);
eval(songName)._y = count * spacing;
count++;
eval(songName).text = sTitle +" - "+path;
eval(songName).setTextFormat(t);
}
}
}
}
My Question:
1) Why do I have to use the eval() function every time I want to set the property of my new text field? I've tried many different ways, and only eval() works.
2) I know one of my nodes coming from the XML file is going to be very long. How (or can I) set my new text field to "wrap"? Right now my text fields are set up for a width of 300, so this long node is getting cut off, and I want it to drop to the next line.
Thanks!
I'm reading in an XML file, and then want to be able to create a list of song names.
I'm using a function to loop through the XML file and create a text field for each entry.
Here's my function:
function createMenu(xmlFile,medType,medCat) {
var items = xmlFile.firstChild.childNodes; // xml file -> music -> songs array
var count = 0;
var spacing = 20;
for(i=0;i<items.length;i++) {
if(items .nodeName == medType) {
if(items.attributes.category == medCat) {
var sTitle = items .firstChild.firstChild;
var path = items.childNodes[1].firstChild;
var songName:String = "songName"+i;
var t:TextFormat = new TextFormat();
t.color = 0xFFFFFF;
t.size = 12;
t.font = "BitStream Vera Sans";
this.createTextField(songName,this.getNextHighestDepth(),292,100,300,200);
eval(songName)._y = count * spacing;
count++;
eval(songName).text = sTitle +" - "+path;
eval(songName).setTextFormat(t);
}
}
}
}
My Question:
1) Why do I have to use the eval() function every time I want to set the property of my new text field? I've tried many different ways, and only eval() works.
2) I know one of my nodes coming from the XML file is going to be very long. How (or can I) set my new text field to "wrap"? Right now my text fields are set up for a width of 300, so this long node is getting cut off, and I want it to drop to the next line.
Thanks!