>> What I need it to target a specific sequence of nodes.

You can do that with my function as well - just pass in the sequence you want 
to target.

 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: Sunday, August 14, 2011 9:40 AM
To: Flash Coders List
Subject: Re: [Flashcoders] Simplify XML Call

> From: Taka Kojima <t...@gigafied.com>

> To: Flash Coders List <flashcoders@chattyfig.figleaf.com>
> Sent: Sunday, August 14, 2011 4:24 AM
> Subject: Re: [Flashcoders] Simplify XML Call

> 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(); }

I modified your code to correct an oversight or two like this:

        private function getNumItems(level, xml):int
        {
            var levelXML:XMLList = xml.menu;
            for(var i:int = 0; i < level - 1; i ++)
            {
           
     levelXML = levelXML.item[whichItems[i]] as XMLList;
                trace(String(levelXML));
            }
            return levelXML.length();
        }

The problem here is that it traces null because you can't convert a string into 
an XMLList and, of course, you can't assign a string to an XMLList either, 
which is why I tried the conversion. (I also tried casting levelXML as a 
wildcard with the same result: null.)

Regarding Jason's code, 

        private function countItems(xmlNode:XML):void
        {
            var total:int = 0;
            var xmlChildren:XMLList = xmlNode.children();
            if(xmlChildren.length() > 0)
            {
                for each (var xmlNode:XML in xmlChildren)
                {
                    total++;
                    countItems(xmlNode); //The recursive call
                }
            }
            trace("totalItems2: ", total);
        }

it doesn't do what I need. What I need it to target a specific sequence of 
nodes. Let's suppose I have the following xml:

<data>
    <item>
        <label><![CDATA[Bracelets]]></label>
        <item>
            <label><![CDATA[Hook Bracelets]]></label>
            <item>
                <label><![CDATA[one]]></label>
            </item>
            <item>
                <label><![CDATA[two]]></label>
                <item>
                    <label><![CDATA[three]]></label>
                </item>
            </item>
        </item>
</data>

Perhaps it would clarify things to state I'm building a drop-down menu. So the 
client mouses over "Bracelets". Out pops "Hook Bracelets". She mouses over that 
and out pops "one" and "two". In order to accomplish this, I need to discover 
which node is being moused over, in this case:

item[0].item[0]

but clearly it could just as easily be:

item[46].item[27]

and I could care less about the rest of the tree. Having said as much, my 
revised code:

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

does, in fact, appear to work :))
Thanks again,
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