sorry a couple of typos... the function should be:

function createPeople (_xml:*):void
{
      var xmlList:XMLList=_xml.children();

      for each (var fn_xml in xmlList) {
           createPeople(fn_xml);
           trace(item_xml.personFirstName);
       }
}

________________________________________
From: [email protected] 
[[email protected]] On Behalf Of Merrill, Jason 
[[email protected]]
Sent: Friday, March 19, 2010 4:07 PM
To: Flash Coders List
Subject: RE: [Flashcoders] Recursive:Part II

I would write the XML this way instead:

<people>
    <person firstName'"Bob" lastName="Smith">
          <person firstName="Timmy" lastName="Smith" />
          <person firstName="Jenny" lastName="Jones" >
               <person firstName="Sal" lastName="Stephens" />
        </person>
    </person>
    <person firstName="Tom" lastName="Williams">
        .etc.

Also, recursive functions call themselves - and then break when some
value or condition is reached.... for yours, add to your object, and
then check to see if there are child nodes in the xml below it, if so,
call the function again to add more, if not, break out of the function.
However, this will only get you through the top level nodes and one of
the top level nodes's sub nodes - not the others - I actually can't
think of how to get into the OTHER sub-nodes - though I know there are
people on this list who do. I know what some people do is make the first
pass on the first level, then the second pass on the second, and so on,
adding to the object as they go.  Don't ask me to send you an example
though.

Recursive functions are also quite hard to wrap your head around. :)

Jason Merrill

Bank of  America  Global Learning
Learning & Performance Solutions

Join the Bank of America Flash Platform Community  and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)






-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Lehr,
Theodore
Sent: Friday, March 19, 2010 3:54 PM
To: Flash Coders List
Subject: [Flashcoders] Recursive:Part II

So I have this xml:

<allPeople>
    <person>
          <personFirstName>Bob</personFirstName>
          <personLastName>Smith</personLastName>
          <person>
               <personFirstName>Timmy</personFirstName>
               <personLastName>Smith</personLastName>
          </person>
          <person>
               <personFirstName>Jenny</personFirstName>
               <personLastName>Smith</personLastName>
          </person>
    </person>
    <person>
          <personFirstName>Tom</personFirstName>
          <personLastName>Williams</personLastName>
          <person>
               <personFirstName>Sa</personFirstName>
               <personLastName>Williams</personLastName>
          </person>
    </person>

To start I am just trying to recursively go through this to grab the
first names. I am trying:

createPeople(peopleXML)

function createPeople (_xml:*):void
{
      var xmlList:XMLList-_xml.children();

      for each (var fn_xml in xmlList) {
           createChart(fn_xml);
           trace(item_xml);
       }
}


I am wondering - am I on the right track? Does the xml look well-formed
for doing what I am trying to do?

Thanks!
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to