dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Reading XML Attribute in PSListBox

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Location
    Hannover, Germany
    Posts
    164

    Reading XML Attribute in PSListBox

    Hi guys, I have been at this stupid problem for days and before I save ANOTHER version that used to work and now doesn't, I am turing to you. Please, please help me!

    I'm trying to populate a PSListBox with node attributes from an xml file. I had the names in before, but as soon as I tried to figure out how to ChangeHandler when the user clicks on a name, it went on strike and now even the names don't come up in the lisbox. Can someone please take a look at my script and tell me what I am doing wrong???

    Thanks! miakazi

    pdfs_xml = new XML();
    pdfs_xml.ignoreWhite = true;
    pdfs_xml.onLoad = fillBox;
    pdfs_xml.load("pdfs_2.xml");
    titelName = "Technical Information";

    function fillBox(success) {
    if (success) {
    var listItem = pdfs_xml.firstChild.childNodes;
    pdfNames = new Array();
    var ThisNode;

    //get array information
    for (var i=0; i < listItem.length; i++) {
    ThisNode = listItem.childNodes[i];
    pdfNames= ThisNode[i].attributes.pdfNAME;

    pdf_listbox.addItem(pdfNames[x]);
    trace(listItem.length);
    trace(listItem.pdfNames[x]);
    }
    }
    }
    openPDF = function(c){
    pdf_listbox.getSelectedItem.pdfNames[i];
    fscommand("exec", i + ".exe");
    trace(pdfNames[i]+".exe");
    }
    pdf_listbox.setChangeHandler("openPDF",this);




    stop();

  2. #2
    Senior Member
    Join Date
    Oct 2000
    Location
    Hannover, Germany
    Posts
    164
    am I talking to myself here????

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Location
    Hannover, Germany
    Posts
    164
    I'm not sure, but it seems that the XML parser is reading the number of objects, but not the attribute "PDFName". I have a trace for

    trace(listItem.length);
    trace(listItem.pdfNames[x]);

    and it returns 15 (the length it has!) but undefined for the name...

    I'm not sure where the problem lies...is anyone out there with an idea- I have a presentation with the client on Friday and HAVE to get this solved!!!

    Thanks!
    miakazi

  4. #4
    Member
    Join Date
    Aug 2000
    Posts
    37

    XML attributes

    When youi look at the documentation for the xml.attributes it returns an associative array, not the type of array you are thinking about. Normally, you think of an array[i] where i is a number index. xml.attributes does not work that way. It grabs the attributes and associates them as name pair. If your xml looked like:

    <node name="test" path="http://"></node>

    if you do a xml.attributs on the node, the array would appear as follow in memory:
    attributes[name] = "test"
    attributes[path] = "http://"

    Because the index is not a number, you can not loop through the array.
    Because the index is not a number, instead of following the normal standard for arrays, macromedia just add the index as a obect identifer. Therefore, you cannot access the array like attributes[name], The values is undefined. You will need to call directly to the array index by xml.attributes.name or xml.attributes.path. The value of the attribute will then be return.

    Hope this helps.

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