dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Multiple Text Boxes Help

Hybrid View

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    160

    Multiple Text Boxes Help

    I'm trying to get values from an XML document into flash ...
    code:

    profile_xml = new XML();
    profile_xml.onLoad = Start;
    profile_xml.load("XML_Files/profile.xml");
    profile_xml.ignoreWhite = true;

    // Intialize variables

    function Start(success) {
    if (success == true) {
    rootNode = profile_xml.firstChild; // References xml doc tree

    firstClass = rootNode.firstChild; // References first class


    currentClass = firstClass;

    totalClasses = currentClass.childNodes.length; // Counts amount of classes

    trace(totalClasses);

    /** Outputs for flash **/
    displayName = currentClass.firstChild.attributes.text;

    displayAge = currentClass.firstChild.nextSibling.attributes.tex t;

    displayStatus = currentClass.firstChild.nextSibling.nextSibling.at tributes.text;

    displayAlias = currentClass.firstChild.nextSibling.nextSibling.ne xtSibling.attributes.text;

    displayTitle = currentClass.firstChild.nextSibling.nextSibling.ne xtSibling.nextSibling.attributes.text;

    displayEmploy = currentClass.firstChild.nextSibling.nextSibling.ne xtSibling.nextSibling.nextSibling.attributes.text;

    displayInspirations = currentClass.firstChild.nextSibling.nextSibling.ne xtSibling.nextSibling.nextSibling.nextSibling.attr ibutes.text;

    displayDescription = currentClass.firstChild.nextSibling.nextSibling.ne xtSibling.nextSibling.nextSibling.nextSibling.next Sibling.attributes.text;
    /**/
    }
    }



    but I have to keep writing the ".nextSibling" to get the proper value ... is there of doing it with writing the ".nextSibling" over and over again ....

    here is the XML file

    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>

    <my_profile>

    <profile section="about_me">
    <name text="Steven"></name>
    <age text="21"></age>
    <status text="Single"></status>
    <alias text="test"></alias>
    <title text="Web Developer, Programmer"></title>
    <employed text="Work></employed>
    <inspirations text="Friends, Nature"></inspirations>
    <description text="Des"></description>
    </profile>
    </my_profile>
    Can anybody help me?

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Australia, Adelaide (SA)
    Posts
    97
    Hi stvsfx,

    First, here's a helper function to make it easier:
    code:

    XMLNode.prototype.selectSingleNodeByName = function( nodeName )
    {
    for( var i = 0; i < this.childNodes.length; i++ )
    {
    if( this.childNodes[i].nodeName == nodeName )
    {
    return this.childNodes[i];
    }
    }
    // if we got here, we didn't find it!
    return null;
    };


    Now your code is as simple as this:
    code:

    profile_xml = new XML();
    profile_xml.onLoad = Start;
    profile_xml.load("XML_Files/profile.xml");
    profile_xml.ignoreWhite = true;

    // Intialize variables

    function Start(success) {
    if (success == true) {
    rootNode = profile_xml.firstChild; // References xml doc tree

    firstClass = rootNode.firstChild; // References first class


    currentClass = firstClass;

    totalClasses = currentClass.childNodes.length; // Counts amount of classes

    trace(totalClasses);

    /** Outputs for flash **/
    displayName = currentClass.selectSingleNodeByName( 'name' ).attributes.text;

    displayAge = currentClass.selectSingleNodeByName( 'age' ).attributes.text;

    displayStatus = currentClass.selectSingleNodeByName( 'status' ).attributes.text;

    displayAlias = currentClass.selectSingleNodeByName( 'alias' ).attributes.text;

    displayTitle = currentClass.selectSingleNodeByName( 'title' ).attributes.text;

    displayEmploy = currentClass.selectSingleNodeByName( 'employed' ).attributes.text;

    displayInspirations = currentClass.selectSingleNodeByName( 'inspirations' ).attributes.text;

    displayDescription = currentClass.selectSingleNodeByName( 'description' ).attributes.text;
    /**/
    }
    }


    Hope this helps!
    Tim Walters
    Senior Developer
    XML Evangelist
    "XML isn't a language, it's a way of life!"

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