all groups > flash actionscript > november 2004 >
You're in the

flash actionscript

group:

Problem with Textfield and XML


Problem with Textfield and XML stilldrunk
11/27/2004 10:03:20 PM
flash actionscript:
I'm not sure what my problem is. I'm parsing an XML file and creating
textfields in AS based on that. I did a trace and found Flash is parsing the
XML and finishing it also gives me the correct text I'm looking for. And when I
check the debugger the correct movieclips are created successfully so I don't
think it's an issue with me creating clips on the same levels. So I'm not sure
why the text will not appear when I test this. Here is my code:

function parseXML(){
trace("parse called");
rootXML = this.firstChild;
child1XML = rootXML.childNodes;
for(var i=0;i<child1XML.length;i++){
child2XML[i] = child1XML[i].childNodes;
var cnn = child1XML[i].nodeName.toLowerCase();
if(cnn == "header"){ // Handle
<HEADER> node
buildMenu(i); // Handle
<HEADER> children
}
}
trace("parse done");
}

function buildMenu(j) {
createEmptyMovieClip("allMenus", 1000);
allMenus.createEmptyMovieClip("menu_"+j, j);
menuItem = eval("allMenus.menu_"+j);
menuItem.createEmptyMovieClip("menuHeader", 1);
menuItem.menuHeader.id = j;
menuItem.menuHeader.menuOpen = false;
menuItem.menuHeader.createEmptyMovieClip("headerText", 2);
menuItem.menuHeader.headerText.createTextField("headerTextItem", 5, 0, 0, 20,
20);
objHeader = eval(menuItem.menuHeader.headerText.headerTextItem);
objHeader.html = true;
objHeader.wordWrap = false;
objHeader.selectable = false;
objHeader.border = false;
objHeader.embedFonts = true;
objHeader.htmlText = child1XML[j].attributes.name; //doesn't seem to work
trace("child1XML:"+ child1XML[j].attributes.name); //returns the correct
text
trace("textWidth:"+objHeader.textWidth); // returns NULL
objHeader._width = objHeader.textWidth + 5;
}

rootXML = new XML(); // Root
"element" XML
child1XML = new Array(); // Level 1
XML
child2XML = new Array(); // Level 2
XML
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = parseXML;
myXML.load("menuEnglish.xml");
stop();
Re: Problem with Textfield and XML J_o_h_n_n_y
11/27/2004 10:36:33 PM
"// returns Zero not 5. Huh?" - When you set the _width, you are setting the
scale, not the real width. Try using UIObject.setSize(w,h) instead.

As for the other issue... not really sure. Try using "objHeader.htmlText =
child1XML[j].attributes.name.toString();" instead maybe?
Re: Problem with Textfield and XML stilldrunk
11/27/2004 10:54:23 PM
That's a good point about the scale. Thanks. But the toString didn't work
either. Doesn't make sense why. This weird stuff happens all the time to me.
It's like Flash knows 'Hey, it's that guy again, let's make sure whatever he
does won't work.'
Re: Problem with Textfield and XML J_o_h_n_n_y
11/27/2004 11:03:35 PM
Haha, we all know the feeling. :p

Question for ya though... maybe it doesn't have anything to do with the XML
but the targetting to the textfield rather.

Does this:
menuItem.menuHeader.headerText.headerTextItem.text = "Hey, I'm in a menu";
do anthing?
Re: Problem with Textfield and XML NSurveyor
11/27/2004 11:08:12 PM
Just to see if it's a problem with the XML or your text box, replace:
objHeader.htmlText = child1XML[j].attributes.name;
with:
objHeader.htmlText = "<B>THE XML DOESN'T WORK</B>"

If you see that text, then you know there is a problem with the XML, and if
you don't see the text, then there is probably some referencing problem.
Re: Problem with Textfield and XML stilldrunk
11/27/2004 11:36:17 PM
Yeah, I tried what both you guys suggested. No luck. I guess it's a reference
problem. I'll rebuild it and take it step by step to see where the reference
breakdown is. I was hoping something would stick out to someone else before I
had to do that. Oh well.
Re: Problem with Textfield and XML NSurveyor
11/27/2004 11:51:28 PM
Re: Problem with Textfield and XML stilldrunk
11/28/2004 1:17:59 AM
Re: Problem with Textfield and XML NSurveyor
11/28/2004 1:32:57 AM
AddThis Social Bookmark Button