1 Reply Latest reply on Jan 25, 2010 3:10 PM by CMcM00

    Trouble with XML-related data types

    CMcM00

      Hi -

       

      I'm having a lot of trouble getting data out of a XMLListCollection object and don't understand since it seems rather unintuitive.

       

      Inside of an ItemRenderer, I have a block of XML in my 'data' property.

       

      If I look at this in the debugger, it looks something like this:

       

      data
         <Record>
            <Links>
               <Link>
                   http://www.google.com
               <Link>
                   http://www.yahoo.com
      
      

       

       

      Ok. So in my itemrenderer, I can put in a trace that looks like this:

       

      trace(data.Links);
      

       

      Which prints this in the console window:

       

      <Links>
        <Link>http://www.google.com</Link>
        <Link>http://www.yahoo.com</Link>
      </Links>

       

      First off, I find it rather unintuitive that you access this by data.Links instead of data.Record.Links, but whatever - at least I got this far.

       

      Now, lets say I wanted to test whether Links had any children. Maybe this record has no links, maybe it has 10.

       

       

      None of these constructs work:

       

      trace(data.Links.length);
      
      trace(data.Record.Links.length);
      
      var links:XMLList = data.Links.children() as XMLList;
      
      var links:XMLList = data.Links as XMLList;
      
      var links:Object = data.Links as Object;
      
      var links:Class = data.Links as Class;
      
      var links:* = data.Links;
      
      

       

      What's the magic trick necessary to navigate this data object?

      I want to iterate over all links in the Record and create LinkButton objects for each of them, then add them to my object with addChild();

       

      I can't even figure out the syntax to test for the number of links in the <Links> section.

       

      Thanks.

        • 1. Re: Trouble with XML-related data types
          CMcM00 Level 1

          Ok looks like this works

           

          var links:XMLList = new XMLList(data.Links.children());
          trace(links.length());
          trace(links[0]);
          
          

           

          Not sure why you have to create it with new().  I would have thought 'links' would just be a pointer to that data instead of allocating new memory for a copy.