Creating Multiple TextFields in runtime AS2
Posted
by ortho
on Stack Overflow
See other posts from Stack Overflow
or by ortho
Published on 2010-03-24T22:47:04Z
Indexed on
2010/03/24
22:53 UTC
Read the original article
Hit count: 346
Hi lads, I have an issue generating multiple text fields in AS2. My AS2 Flash application calls database (via PHP) and then receives XML file that contains a few objects. All I want to do is to loop throught this XML objects and then create a TextField (actually a Component that contains graphics and TextField, but this will come later) based on the information from XML object.
I know that I can create something like: _root.createTextField("myText1",1,0,0,100,20); myText1.text = "this is text ONE";
_root.createTextField("myText2",2,0,30,100,20); myText2.text = "this is text TWO"; which will result in 2 text fields, but the problem is when I try to create it dynamicly (e.g. I have item: myNode[0].attributes.name (but when I use it in: _root.createTextField(myNode[0].attributes.name, 1, 0, 0, 100, 20), then I got compile error).
var myXML:XML = new XML();
myXML.ignoreWhite=true; myXML.load("tekst.xml"); var tekst:String = new String(); myXML.onLoad = function(success){ if (success){ var myNode = myXML.firstChild.childNodes; for (i=0; i
trace("height: "+myNode[i].attributes.height); trace("color: "+myNode[i].attributes.color); trace(myNode[i].firstChild.nodeValue); } } }
This actualy traces the values and I can actualy use them when creating the component, but it doesn't create the component that has the same name (obviously both instances point to the same object so the last is only visible).
Please help, I tried many things, but no joy.
Thank you in advance.
© Stack Overflow or respective owner