A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Help with variable in Array, XML

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1

    Help with variable in Array, XML

    I think I've been staring at my code too long and I'm stuck. Can anyone help me?

    I basically need to load information from an XML. Then depending on which button is clicked(apartment in a building) that specific info from the xml needs to load in a txt field.

    Here is my actionscript and xml code. I'm stuck on how to assign " i " to each apartment in the building.

    Actionscript Code:
    name = [];
    sqft = [];
    price = [];
    avail = [];

    //Load XML File
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("../xml/unit_specs.xml");
    function loadXML(loaded) {
    if (loaded) {
        specs = this.firstChild.childNodes;
        len = specs.length;
        for(var i=0;i!=len;i++){
        name[i] = specs[i].childNodes[0].firstChild.nodeValue;
        sqft[i] = specs[i].childNodes[1].firstChild.nodeValue;
        price[i] = specs[i].childNodes[2].firstChild.nodeValue;
        avail[i] = specs[i].childNodes[3].firstChild.nodeValue;
        }
    //    trace (name);
    } else {
          trace("file not loaded!");
    }}

    There are quite a few more apartments than this but here is how I have it set up.

    Code:
    <specs>
        <unit>
            <name>1A</name>
            <sqft>1,033</sqft>
            <price>$1,200</price>
            <avail>Jan 2012</avail>
        </unit>
        <unit>
            <name>1B</name>
            <sqft>613</sqft>
            <price>$900</price>
            <avail>Jan 2012</avail>
        </unit>
        <unit>
            <name>1C</name>
            <sqft>419</sqft>
            <price>$700</price>
            <avail>Jan 2012</avail>
        </unit>
        <unit>
            <name>1D</name>
            <sqft>508</sqft>
            <price>$800</price>
            <avail>Jan 2012</avail>
        </unit>
        <unit>
            <name>2B</name>
            <secdep>$900</secdep>
            <price>$900</price>
            <avail>Jan 2012</avail>
        </unit>
        <unit>
            <name>2N</name>
            <sqft>1,033</sqft>
            <price>$1,400</price>
            <avail>Jan 2012</avail>
        </unit>
    </specs>

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    For instance, for you building 1A, assuming it's a button, put this code on it:

    Actionscript Code:
    on(press){
        name_textfield.text = name[0];
        sqft_textfield.text = sqft[0];
        price_textfield.text = price[0];
        avail_textfield.text = avail[0];
    }

    and then the same with the other buttons, for instance for 1B, just change 0 to 1
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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