开发者

Finding the position of occurring of a node whose attributes values we have in AS3

I have an XML

 <p id="section02_01"/>
 <p id="section02_02"/>
 <p id="section02_03"/>
 <p id="section02_04"/>
 <p id="section02_05"/>
 <p id="section02_06"/>
 <p id="section02_07"/>
     <p id="section02_08"/>

I have the value of id as section02_05. How can I find the position of corresponding p node using XML or E4X. Assume that the root n开发者_开发问答ode for this.


If have understand your question, you can use the method childIndex

var xml:XML=<xml>
<p id="section02_01"/>
 <p id="section02_02"/>
 <p id="section02_03"/>
 <p id="section02_04"/>
 <p id="section02_05"/>
 <p id="section02_06"/>
 <p id="section02_07"/>
 <p id="section02_08"/>
</xml>

trace(xml.p.(@id=="section02_05").childIndex())


Well first off you can parse for that node using an attribute filter as described here: http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg6.htm

Then once you have that node you can find it's position in the XML tree by using parent()n: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XMLList.html#parent%28%29

Write a recursive function that both goes to the node's parent and keeps a count of how many times it has recursed*, and then it stops recursing* when parent() returns "undefined".

*Is this a real word? I hope you get what I mean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜