Creating Multiple TextFields in runtime AS2
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 t开发者_JAVA技巧hat 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.
theoretically although the trace function does indeed work out correctly, it is because it is formatted to string automatically. your use of the node in the createTextField might be passing as an XML and therefore not useable. try using _root.createTextField(myNode[0].attributes.name.toString(), 1, 0, 0, 100, 20)
instead and see what happens.
精彩评论