>> Then I think I hit on what Jason was suggesting:

Not really. :) I think you're over complicating this.  This is all I was 
suggesting you do from my original suggestion, it's pretty straightforward 
(this is a test case you could copy paste and run):

//DUMMY DATA:
var myXML:XML = <data>
        <functionalarea type="amountKeying" 
backgroundImage="images/background.png">
                <exercises>
                        <exercise type="NoviceRDS">
                                <keyingItems>
                                        <keyingItem 
fileURL="assets/images/simulations/ATC/atc_701201045.png" 
invertedFileURL="myImages/myFileInverted1.png" legible="true" amount="78400" />
                                        <keyingItem 
fileURL="myImages/myFile2.png" invertedFileURL="myImages/myFileInverted2.png" 
legible="false" amount="743600" />
                                        <keyingItem 
fileURL="myImages/myFile3.png" invertedFileURL="myImages/myFileInverted3.png" 
legible="true" amount="3213212" />
                                        <keyingItem 
fileURL="myImages/amountkeying/myFile4.png" 
invertedFileURL="myImages/myFileInverted4.png" legible="true" amount="43242323" 
/>
                                        <keyingItem 
fileURL="myImages/myFile5.png" invertedFileURL="myImages/myFileInverted5.png" 
legible="true" amount="78400" />
                                        <keyingItem 
fileURL="myImages/myFile6.png" invertedFileURL="myImages/myFileInverted6.png" 
legible="false" amount="342132" />
                                        <keyingItem 
fileURL="myImages/myFile7.png" invertedFileURL="myImages/myFileInverted7.png" 
legible="true" amount="78400" />
                                </keyingItems>
                        </exercise>
                        <exercise type="ExpertRDS">
                                <keyingItems>
                                        <keyingItem 
fileURL="assets/images/simulations/ATC/atc_701201045.png" 
invertedFileURL="myImages/myFileInverted1.png" legible="true" amount="78400" />
                                        <keyingItem 
fileURL="myImages/myFile2.png" invertedFileURL="myImages/myFileInverted2.png" 
legible="false" amount="743600" />
                                        <keyingItem 
fileURL="myImages/myFile3.png" invertedFileURL="myImages/myFileInverted3.png" 
legible="true" amount="3213212" />
                                        <keyingItem 
fileURL="myImages/amountkeying/myFile4.png" 
invertedFileURL="myImages/myFileInverted4.png" legible="true" amount="43242323" 
/>
                                        <keyingItem 
fileURL="myImages/myFile5.png" invertedFileURL="myImages/myFileInverted5.png" 
legible="true" amount="78400" />
                                        <keyingItem 
fileURL="myImages/myFile6.png" invertedFileURL="myImages/myFileInverted6.png" 
legible="false" amount="342132" />
                                        <keyingItem 
fileURL="myImages/myFile7.png" invertedFileURL="myImages/myFileInverted7.png" 
legible="true" amount="78400" />
                                </keyingItems>
                        </exercise>
                </exercises>
        </functionalarea>
</data>

//RECURSIVE FUNCTION:

var totalItems:uint = 0;

function countItems(xmlNode:XML):void
{
        var xmlChildren:XMLList = xmlNode.children();
        if(xmlChildren.length() > 0)
        {
                for each (var xmlNode:XML in xmlChildren)
                {
                        totalItems++;
                        countItems(xmlNode); //The recursive call
                }
        }
}

countItems(myXML);

//RESULT:
trace(totalItems);//Traces 20 - there are 20 nodes in the given XML from the 
root down.  

Instead of the root, you could start farther in too if you wanted, i.e.:

var exercisesXML:XML = myXML.functionalarea[0].exercises[0];
countItems(exercisesXML);
trace(totalItems); //traces 18 - there are 18 nodes from that level down.

If that's not exactly what you need, it would seem the general concept could be 
modified to fit your needs. Hope that helps,

 Jason Merrill
 Instructional Technology Architect II
 Bank of America  Global Learning 





_______________________


-----Original Message-----
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of John Polk
Sent: Saturday, August 13, 2011 5:58 PM
To: Flash Coders List
Subject: Re: [Flashcoders] Simplify XML Call

> From: Henrik Andersson <he...@henke37.cjb.net>

> To: Flash Coders List <flashcoders@chattyfig.figleaf.com>
> Sent: Saturday, August 13, 2011 3:37 PM
> Subject: Re: [Flashcoders] Simplify XML Call
>
> There is still no eval function.

I know there is no eval fn. Jason Merrill earlier wrote: "You just need a 
recursive loop to do this.  So I would write a function that handles each node 
level individually, adding to a class-level private property called something 
like, _totalItems." I tried googling [as3 "recursive loop" xml node] without 
much luck. Then I think I hit on what Jason was suggesting:

            var x:*;
            x = xml.menu.item[whichItems[0]];
            var levelsLeft:int = level - 2;
            var q:int = 4;
            while(levelsLeft--)
            {
                x = x.item[whichItems[q]];
                q--;
            }
            trace('xxx', x.item.length());

The problem is that for reasons that don't bear explaining I'm not ready to 
test this beyond the first level today :-} But I think it (or some tweak) 
should work (and I'll clean out that wildcard var).

Thanks,
John
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

----------------------------------------------------------------------
This message w/attachments (message) is intended solely for the use of the 
intended recipient(s) and may contain information that is privileged, 
confidential or proprietary. If you are not an intended recipient, please 
notify the sender, and then please delete and destroy all copies and 
attachments, and be advised that any review or dissemination of, or the taking 
of any action in reliance on, the information contained in or attached to this 
message is prohibited. 
Unless specifically indicated, this message is not an offer to sell or a 
solicitation of any investment products or other financial product or service, 
an official confirmation of any transaction, or an official statement of 
Sender. Subject to applicable law, Sender may intercept, monitor, review and 
retain e-communications (EC) traveling through its networks/systems and may 
produce any such EC to regulators, law enforcement, in litigation and as 
required by law. 
The laws of the country of each sender/recipient may impact the handling of EC, 
and EC may be archived, supervised and produced in countries other than the 
country in which you are located. This message cannot be guaranteed to be 
secure or free of errors or viruses. 

References to "Sender" are references to any subsidiary of Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Attachments that are part of this EC may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you 
consent to the foregoing.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to