dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: help, getting XML attributes

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    50

    help, getting XML attributes

    can some 1 teach me how to get attributes from XML files.. I saw the tutorial on gotoandlearn but when i try to incorperate it to my needs it dont work.
    this is my first at any XML...

    PHP file generate this XML
    <?xml version="1.0"?>
    <photo>
    <item img="img1.jpg" comment="text1" />
    <item img="img2.jpg" comment="text2" />
    </photo>


    Actionscript
    var tp:XML = new XML();
    tp.ignoreWhite = true;

    tp.onLoad = function (success) {
    if (success) {
    trace(this.firstChild.childNodes.attributes.img);
    }
    }
    tp.load('photoloader.php');

    comes back as undefned, sigh*

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    That example seems to assume there is only one node in the xml (when the example posted has two).

    To trace all the image attributes try:

    Code:
    var tp:XML = new XML();
    tp.ignoreWhite = true;
    
    tp.onLoad = function (success) {
    if (success) {
    	 mycount = this.firstChild.childNodes;
    	for (var i=0;i<mycount.length;i++){
    trace(this.firstChild.childNodes[i].attributes.img);
    	}
    }
    }
    tp.load('photoloader.php');
    If you really do only want to load that first image in the list of two...use:

    Code:
    var tp:XML = new XML();
    tp.ignoreWhite = true;
    
    tp.onLoad = function (success) {
    if (success) {
    trace(this.firstChild.childNodes[0].attributes.img);
    }
    }
    tp.load('photoloader.php');

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    50
    thanks! that works!
    wow, i didnt realised you cant load a php file when publishing inside flash

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    We aim to please

    You can hit your php backend while testing locally as long as you use the fully qualified address

    http://pathto.someserver.com/mybackend.php

    When you upload to your server revert back to relative urls

    mybackend.php

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