I don't even know why I'm responding to this, but. Ktu gave you the answer
yet you seemed to ignore it? You don't need an eval at all.

function getNumItems(level:int, xml:XML):int{
 var levelXML:XML = xml.menu;
 for(var i:int = 0; i < level; i ++){
 levelXML = levelXML.item[whichItems[level]];
}
return levelXML.length();
}

does exactly what this would do, if AS3 had an eval:

            var j:String = "xml.menu.item[whichItems[0]]";
            var k:String = new String();
            var l:int = level;
            while (l--)
            {
                k += ".item[whichItems[" + String(l) + "]]";
            }
            totalItems = (j + k);

Taka


On Sat, Aug 13, 2011 at 7:17 PM, Merrill, Jason <
jason.merr...@bankofamerica.com> wrote:

> And here's another recursive function example for XML, slightly different,
> with a more complex structure, showing how to get all values from some
> attributes in an XML file (in this case, firstName and lastName), no matter
> where or how deep they lie:
>
> var peopleXML:XML =
> <people>
>        <person firstName="Bob" lastName="Smith">
>        <person firstName="Timmy" lastName="Smith" />
>                <person firstName="Jenny" lastName="Jones" >
>                        <person firstName="Sal" lastName="Stephens" />
>                </person>
>                <person firstName="Marcia" lastName="Marquez">
>                        <person firstName="Julio" lastName="Rogers"/>
>                </person>
>        </person>
>        <person firstName="Tom" lastName="Williams">
>                <person firstName="Mary" lastName="Jones" />
>                <person firstName="Albert" lastName="Denniston">
>                        <person firstName="Barney" lastName="Elmington" />
>                        <person firstName="Campo" lastName="Fatigua">
>                                <person firstName="Harpo" lastName="Oprah"/>
>                        </person>
>                        <person firstName="Hugo" lastName="Boss">
>                                <person firstName="Benny"
> lastName="Elkins"/>
>                                <person firstName="Sheri"
> lastName="Downing"/>
>                        </person>
>                </person>
>        </person>
>        <person firstName="Marcia" lastName="Marquez">
>                <person firstName="Manny" lastName="Peterson"/>
>        </person>
>        <person firstName="Joe" lastName="Merritt"/>
> </people>;
>
>
> function recurseXML(xml:*):void
> {
>        var xmlList:XMLList = xml.children();
>        for each (var currentNode:* in xmlList)
>        {
>                trace(currentNode.@firstName+" "+currentNode.@lastName);
>                if(currentNode.children()) recurseXML(currentNode);
>        }
> }
>
> recurseXML(peopleXML);
>
> //Traces:
> Bob Smith
> Timmy Smith
> Jenny Jones
> Sal Stephens
> Marcia Marquez
> Julio Rogers
> Tom Williams
> Mary Jones
> Albert Denniston
> Barney Elmington
> Campo Fatigua
> Harpo Oprah
> Hugo Boss
> Benny Elkins
> Sheri Downing
> Marcia Marquez
> Manny Peterson
> Joe Merritt
>
>  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 Merrill, Jason
> Sent: Saturday, August 13, 2011 9:58 PM
> To: Flash Coders List
> Subject: RE: [Flashcoders] Simplify XML Call
>
> >> 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
>
> ----------------------------------------------------------------------
> 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
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to