A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Load Specific Node

  1. #1
    Old man of minimal posts
    Join Date
    Jul 2000
    Location
    Nottingham, UK
    Posts
    230

    Load Specific Node

    Hi all,

    I want to load the contents of a specific node from an XML document on a button click event.

    Basically I've got a world map, and when you click on the button for say South Africa, I want to load the address for our branch in South Africa into the flash Movie.

    Can anyone point me in the right direction?

    I'm currently loading my XML document into a text area component using this:

    myContent = new XML();
    myContent.ignoreWhite = true;
    myContent.load("Licensees.xml");
    myContent.onLoad = function(success) {
    if (success) {
    myText.text = myContent;
    }
    }

    And my XML document follows this structure:

    <Licensee id="2">
    <Continent>Africa</Continent>
    <CompanyName>Probike South Africa (Pty) Limited</CompanyName>
    <Address1>PO Box 2712</Address1>
    <Address2>North End</Address2>
    <Address3>Port Elizabeth</Address3>
    <Address4></Address4>
    <PostCode>6056</PostCode>
    <Country>South Africa</Country>
    <Telephone>+27 (041) 487 1713</Telephone>
    <Fax>+27 (041) 404 8500</Fax>
    <Web>http://www.raleigh.co.za</Web>
    </Licensee>

    Any help you can give me would be greatly appreciated.

    Thanks in advance,

    Highlander

  2. #2
    Old man of minimal posts
    Join Date
    Jul 2000
    Location
    Nottingham, UK
    Posts
    230

    Never Mind

    Sussed it.

    I instantiate the xml object using this

    Code:
    function loadFranchisee(IDNO) {
    	myIDNO = IDNO;
    	var myXML:XML = new XML();
    	myXML.ignoreWhite = true;
    	myXML.onLoad = processXML;
    	myXML.load("Licensees.xml");
    }
    Then tell the textfield which node to display using this:

    Code:
    function processXML(success:Boolean):Void {
    	if (success) {
    		//trace(this.firstChild.childNodes[1].firstChild);
    		//txtAddress.text = this.childNodes[0].childNodes[ID].childNodes[FIELD].childNodes[0];		
    		txtAddress.text = this.childNodes[0].childNodes[myIDNO].childNodes[1].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[2].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[3].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[4].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[5].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[6].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[7].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[8].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[9].childNodes[0];		
    		txtAddress.text = txtAddress.text + this.childNodes[0].childNodes[myIDNO].childNodes[10].childNodes[0];		
    	
    	} else {
    		trace("Error loading xml file.");
    	}
    }

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    for targetting specific nodes you can also use xPath

    have a look at http://www.peachpit.com/articles/art...?p=169633&rl=1 for more info
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member
    Join Date
    Dec 2005
    Location
    Sydney,Australia
    Posts
    101

    Try this old thread

    Hilander,
    Try this similar thread "finding XML node using loop"
    http://board.flashkit.com/board/showthread.php?t=699776
    I explained here with example on how to find specific node. Nenjoy...
    You'll find flash chessgenie at http://www.rootyhillchess.org
    and at my blog page at http://chessgenie.blogspot.com/

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