A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F9/AS3] XML vs XMLList?

  1. #1
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465

    [F9/AS3] XML vs XMLList?

    This is my first time reading XML data into flash, and I am having problems with Flash casting some of my nodes(?) as XMLList with length 1, instead of just using a (non-array) XML object.

    Here's an (incomplete) snippet that shows part of the problem:

    PHP Code:
    - <map>
    - <
    sectors>
      <
    size>4</size
    - <
    sector>
    - <
    cell>
    - <
    vertices>
      <
    size>15</size
    - <
    vertex>
      <
    x>2.486322188449848</x
      <
    y>-0.604863221884498</y
    Imagine f() is a function that accepts an XML as an input. A map contains many sectors, so I agree that dereferencing a sector requires a "[]" operator:

    Code:
    f(map.sectors.sector[0])
    However, each sector has one cell so expect that I can derefence it as a single node:

    Code:
    f(map.sectors.sector[0].cell)
    This throws a runtime error (cannot cast convert). Apparently, this chain of dereferences yields an XMLList, not an XML. When I do:

    Code:
    f(map.sectors.sector[0].cell[0])
    It works properly. It doesn't make sense to me that cell should be promoted from an XML to an XMLList, because there's only one of them within each pair of <sector></sector> tags. This is my first xml experience, so maybe I don't understand how it works yet.

    Here's the complete .xml file, from which the snippet was taken. Is it well formed? Can you tell an obvious reason that cell is being recognized as a list with 1 element, instead of a node that stands alone?
    Attached Files Attached Files

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    I am more the XML crack when it comes to AS1/2, AS3 is way more the beast when it comes to xml so I recently just scrapped the surface

    Imagine f() is a function that accepts an XML as an input
    you can however only return snippets/nodes of that XML object as XMLList type.
    so your function should accept XMLList objects rather than XML (wich contains additional info besides the content of the XML itself)
    PHP Code:
    function f(nodes:XMLList){

    }
    f(map.sectors.sector[0].cell); 
    if I understood your situation and the AS3 xml stuff correct then the Array ".cell" is interpreted as XMLList Object (a Array Object with additional XML methods to quicker work with XML files).
    Whereas a single Array or XMLList element like ".cell[0]" is interpreted as something else (XML in your case?).
    In the past XML was used in just 1 XML object without the special case of the XMLList,- instead there was a method called childNodes wich returned a standard array containing each Objects with attributes like firstChild, attributes,...

    but to be honest,- I´d have to create a new AS3 file to test it out - just used XML twice in AS3 so far. 90% of my flash work is still AS1/2 , AS3 is still optional and only used if really needed. So not really sure if I can help you that well for now (little time pressure here as well)

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