There is some data type confusion going on here.  If you are using the xml
as the data source, how are you getting it into Flex? I strongly suspect you
are letting Flex do its default resultFormat conversion into a tree of
dynamic objects.  Actionscript can't tell the difference between an Object
and an Array with a single element so it opts for object.  You can't get the
length of an object.

 

This, "selectedItem.links.link" is object tree syntax, not XML or
ArrayCollection syntax.

 

There are several solutions.  I advise using resultFormat="e4x", then
processing that xml into an ArrayCollection of strongly typed value objects.

 

Tracy Spratt,

Lariat Services, development services available

  _____  

From: [email protected] [mailto:[email protected]] On
Behalf Of valdhor
Sent: Monday, March 15, 2010 12:53 PM
To: [email protected]
Subject: [flexcoders] Re: I need some basic ActionScript help that I'm
stumped on

 

  

I'm not great with XML (That's more Tracy's forte) but shouldn't it be 

trace(myADG.selectedItem.links.length);

--- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
"Mark" <mark.pusat...@...> wrote:
>
> I'm having an issue with finding the length of the number of children
items in my ArrayCollection. A small part of the xml that is being pulled in
is below. You'll see that I have a node <links> with a child or children
node <link>. If I have 2 or more <link> nodes then the length comes back
with the proper number, but if I only have 1 it comes back as undefined.
Here's my basic function that I'm putting together now.
> 
> private function dgChanged(evt:Event):void {
> if (myADG.selectedItem.links != null) {
> trace(myADG.selectedItem.links.link.length);
> } else {
> trace ("NULL" );
> }
> 
> 
> <items>
> <item>
> <eID>4</eID>
> <eName><![CDATA[3 Event with link]]></eName>
> <sDate>1/2/2010</sDate>
> <eDate>2/18/2010</eDate>
> <sTime>12:00:00 PM</sTime>
> <eTime>3:00:00 PM</eTime>
> <description><![CDATA[Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release of
Letraset sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.]]></description>
> <aName>AIT</aName>
> <cName>Learning</cName>
> <lName>UK</lName>
> <links>
> <link ID="1" description="description of the link" title="Apple"
url="www.apple.com"/>
> </links>
> </item>
> 
> 
> Any ideas as to why I'm getting "undefined"?
> 
> Thanks,
> Mark
>



Reply via email to