xml - Actionscript 2: Get an instance name from a variable string -


i'm trying take text xml file (this text translated later must held externally) , import separate dynamic text boxes in flash (as2). text boxes organised first row (eg r1) page (eg p1) , text line (eg l1), change text in first row, first page, first line you'd enter r1.p1.l1.text = "sometext".

this xml file. first thing need id each <txt> tag , save variable can use text box identifier don't know how!

<?xml version="1.0" encoding="utf-8"?> <txt id="r1.p1.l1">first line of text</txt> <txt id="r1.p1.l2">second line of text</txt> 

the xml called in following function , text boxes should populated accordingly - id has converted instance name; i've tried using variable the_xml_id = this[somevar] couldn't work either...

function getdata() {     var txt:xml = new xml();     txt.ignorewhite = true;     txt.onload = function(success)     {         (i = 0; < txt.childnodes.length; i++){             the_xml_id.text = txt.childnodes[i].childnodes[0];         }     };     txt.load("assets/text/text.xml"); } 

to sum up: need id each <txt> tag in xml file , use text box identifier line of text - appreciated.

if following in onload method:

this['testtext'].text = txt.childnodes[0].childnodes[0]; 

"this" refers xml object. try

_root['testtext'].text = txt.childnodes[0].childnodes[0]; 

anyway approach won't work cant evaluate deeper. suggested in comments, better use xml structure make targeting easier if want keep logic, here working exemple :

// scope of displayobjects, here on main timeline var scope:movieclip = _root;  // id attributes , return related displayobject function gettargetfromid(id:string, scope:movieclip):movieclip {     var target:movieclip = scope;     var path:array = id.split('.');     (var i:number=0;i<path.length;i++) {        target = target[ path[i] ];      }      return target;  }   function getdata():void{   var txt:xml = new xml();   txt.ignorewhite = true;   txt.onload = function(success) {     (i:number = 0; < txt.childnodes.length; i++){        var id:string = txt.childnodes[i].attributes.id;        gettargetfromid(id,scope).text = txt.childnodes[i].firstchild.tostring();     }   }   txt.load("assets/text/text.xml"); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -