This same problem tripped me up as well... I couldn't figure out why I kept
getting XMLList's that contained elements when I was *sure* that the
elements shouldn't be there. I was checking for "list.length > != 0" which
of course was always true as ".length" was undefined for my XML elements.

What I realized (and already knew but just wasn't thinking) was that XML and
XMLList don't have any properties... everything is a method. It does that to
avoid colliding with your own element names. So, whenever you're wanting to
access any "property" of an XML node or XMLList don't forget your parens!

Troy.


On 05 Mar 2007 01:08:04 -0800, allenyoungsjtu <[EMAIL PROTECTED]>
wrote:

  Hi greg h,

Thank you for replying. With your help, my program is OK now. I've found
the problem. In my program, I was using blockXML.block.length, and it
reported a property not found error. I was thinking that it's because of
"block", but now I find the reason is "length".I thoungt
"blockXML.block" should return an Array, but it seems like that the
return type is ArrayCollection or XMLList(I'm not sure), so "length"
cannot be used and "length()" is the right way.

Thanks again for you reply. It really helps.

Allen.


--- In [email protected] <flexcoders%40yahoogroups.com>, "greg h"
<[EMAIL PROTECTED]> wrote:
>
> Hi allenyoungsjtu,
>
> When I run your code, this is what I get returned:
>
> <block id="001">
> <point x="0" y="0"/>
> <point x="50" y="0"/>
> <point x="0" y="50"/>
> </block>
>
> Is this what you meant by "the <block id='001' /> node"? If not,
could you
> please cut and paste in the return value that you would expect given
the
> value of blockXML. Or what are you seeing that leads you to conclude
"it
> turned out that as cannot recognise block as blockXML's property"?
>
> Here is my MXML:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; >
>
> <mx:Script>
> <![CDATA[
>
> [Bindable]
> private var blockXML:XML =
> <blocks>
> <block id='001'>
> <point x='0' y='0' />
> <point x='50' y='0' />
> <point x='0' y='50' />
> </block>
> </blocks>;
>
> ]]>
> </mx:Script>
>
> <mx:TextArea text="{blockXML.block[0]}"
> height="100%"
> width="90%"/>
>
> </mx:Application>
>
> hth,
>
> g
>
> On 3/4/07, allenyoungsjtu [EMAIL PROTECTED] wrote:
> >
> > Hi all,
> >
> > I want to process some xml documents using actionscript. The
document
> > is something like this:
> >
> > [code]
> > private var blockXML:XML =
> > <blocks>
> > <block id='001'>
> > <point x='0' y='0' />
> > <point x='50' y='0' />
> > <point x='0' y='50' />
> > </block>
> > </blocks>;
> > [/code]
> >
> > I thought I could use the statement as follows:
> >
> > [code]
> > blockXML.block[0]
> > [/code]
> >
> > to get the <block id='001' /> node, but it turned out that as cannot
> > recognise block as blockXML's property.
> >
> > Is there something wrong with my approach? Or I just cannot write it
> > in this way? Thanks a lot!
> >
>

Reply via email to