A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Question about displaying childNodes in different textareas

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Posts
    18

    Question about displaying childNodes in different textareas

    Hey guys!
    I'm new to the community!
    I was wondering, I an have this XML file thats set up in this style:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    <profile>
    <id>18771967</id>
    <name></name>
    </profile>
    I would like to have each childNode (i.e. <name>) go into a separate dynamic text area. How would I do this?

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    //--on stage--
    //--dynamic textfields, instance names id,name0,name1,name2

    txtArr = [id,name0,name1,name2]; // add instance names to the array

    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("xmltest.xml");

    _xml.onLoad = function(){
    aNode = this.firstChild.childNodes;
    len = aNode.length;
    for(var n=0;n!=len;n++){
    trace(aNode[n].firstChild);
    txtArr[n].text = aNode[n].firstChild;
    }
    };

    /*--test.xml--
    <?xml version="1.0" encoding="UTF-8" ?> 
    <profile>
    <id>18771967</id>
    <name>Ann</name>
    <name>Bob</name>
    <name>Cyd</name>
    </profile>
    */
    hth

  3. #3
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    thanks!
    So if i had more childnodes in the XML file i could just add dynamic text boxes with different instance names and it would load them in??
    and add them into :
    Code:
    txtArr = [id,name0,name1,name2,lastlogin, info]; // add instance names to the array
    ?? I really appreciate it
    Quote Originally Posted by a_modified_dog
    PHP Code:
    //--on stage--
    //--dynamic textfields, instance names id,name0,name1,name2

    txtArr = [id,name0,name1,name2]; // add instance names to the array

    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("xmltest.xml");

    _xml.onLoad = function(){
    aNode = this.firstChild.childNodes;
    len = aNode.length;
    for(var n=0;n!=len;n++){
    trace(aNode[n].firstChild);
    txtArr[n].text = aNode[n].firstChild;
    }
    };

    /*--test.xml--
    <?xml version="1.0" encoding="UTF-8" ?> 
    <profile>
    <id>18771967</id>
    <name>Ann</name>
    <name>Bob</name>
    <name>Cyd</name>
    </profile>
    */
    hth

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    yes, match the number of textfields in the array
    to the number of nodes in the xml file

  5. #5
    Junior Member
    Join Date
    Nov 2007
    Posts
    18

    Thanks so much!
    Quote Originally Posted by a_modified_dog
    yes, match the number of textfields in the array
    to the number of nodes in the xml file

  6. #6
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    Hey i'm having trouble with loading HTML formatted XML into the textareas. Changing
    PHP Code:
    txtArr[n].txt aNode[n].firstChild
    to
    PHP Code:
    txtArr[n].htmlText  aNode[n].firstChild
    formats some of the text and loads it properly but some of it still loads like it written in the xml file :[
    Any idea how to fix it?
    The acutal XML Files is this
    PHP Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <profile>
      <id>18771967</id> 
      <fullname>73c%7C%26trade%3B+%3D+%5BTed%2C+Teddy%2C+Theo%2C+Theodore.+wtf%21%5D</fullname> 
      <address>url</address> 
      <profilephoto>http://b2.ac-images.myspacecdn.com/00773/28/20/773890282_m.jpg</profilephoto> 
      <headline>lol</headline> 
      <lastlogin>11/7/2007</lastlogin> 
      <gender>Male</gender> 
      <age>16 years old</age> 
      <town>Good+ol%27+127.0.0.1</town> 
      <country>United+States</country> 
      <interests>-</interests> 
      <music>-</music> 
      <films>%3Cdiv+style%3D%22display%3Anone%3B%22%3E%3C%2Fdiv%3E</films> 
      <television>%3Cdiv+style%3D%22display%3Anone%3B%22%3E%3C%2Fdiv%3E</television> 
      <books>%3Cdiv+style%3D%22display%3Anone%3B%22%3E%3C%2Fdiv%3E</books> 
      <heroes>%3Cdiv+style%3D%22display%3Anone%3B%22%3E%3C%2Fdiv%3E</heroes> 
      <aboutme>ey-o</aboutme> 
      <whotomeet>ey-o</whotomeet> 
      <mystatus>Single</mystatus> 
      <herefor>Networking, Friends</herefor> 
      <myorientation>Straight</myorientation> 
      <hometown>Good+ol%27+127.0.0.1</hometown> 
      <bodytype>5' 11" / Slim / Slender</bodytype> 
      <ethnicity>White / Caucasian</ethnicity> 
      <religion>N/a</religion> 
      <zodiacsign>Pisces</zodiacsign> 
      <smokedrink>N/a</smokedrink> 
      <children>Someday</children> 
      <education>High school</education> 
      <occupation>McDonalds+Crew+Trainer</occupation> 
      <income>Less than $30,000</income> 
      <layout>http://members.cox.net/tass2001/tech5.swf</layout> 
      </profile>
    && Yes its for myspace
    Last edited by tass2001; 11-18-2007 at 08:13 PM.

  7. #7
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    Okay i figured out what I need is to add the unescape function to some of the textboxes, how would I do that?

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    something like this ??

    str = aNode[n].firstChild;
    str = unescape(str);
    txtArr[n].htmlText = str;

  9. #9
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    Quote Originally Posted by a_modified_dog
    something like this ??

    str = aNode[n].firstChild;
    str = unescape(str);
    txtArr[n].htmlText = str;
    ! Yes!

  10. #10
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    Okay I'm sorry one more problem i'm having, some of the text boxes are going inside movie clips and when i load the movie they appear empty. How would I tell flash that these text boxes are inside movie clips so it will load the information into them?

  11. #11
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you'll have to use a different approach -
    PHP Code:
    _xml = new XML(); 
    _xml.ignoreWhite true
    _xml.load("xmltest.xml"); 

    arr = []; // create an array

    _xml.onLoad = function(){ 
    aNode this.firstChild.childNodes
    len aNode.length
    for(var 
    n=0;n!=len;n++){ 
    arr[n] = aNode[n].firstChild// load the array

    populateText(); // xml is loaded, array is loaded, populate the textfields
    }; 

    function 
    populateText(){
    _root.field1.text arr[0]; // textfield on root
    _root.clip1.field2.text arr[1]; // textfield in movieclip
    _root.clip2.clip2a.field3.text arr[2];  // textfield in nested movieclip
    }; 
    use Test Movie / List Variables to view the array

  12. #12
    Junior Member
    Join Date
    Nov 2007
    Posts
    18
    That Works Great
    One small little kink left to iron out though, I have my page set up with a main MC in the middle of the stage and tabs out to the side. When a tab is clicked it loads that particular keyframe of the MC on the stage i.e. Clicking the info tab is set to load the say, 2nd keyframe of the MC. Well when I add the dynamic textboxes in any other keyframe but keyframe 1 and I click a tab that loads say the 2nd keyframe the textboxes show up but with no info in them . Keep in mind that the information in keyframe one loads fine but when I click to go back to keyframe 1 the info has disappeared.

  13. #13
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    add a frame action to 2nd keyframe of movieclip -

    field1.text = _root.arr[3];

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center