Posted By

dxc381 on 08/06/10


Tagged

xml recursive as3 infinite


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

thastyle
alptugan
tspitzr
miiisha


AS3 Recursive Function


 / Published in: ActionScript 3
 

Run through infinite xml child nodes.

  1. package com.dxc381{
  2.  
  3. //import flash classes
  4. import flash.display.Sprite;
  5.  
  6. public class InfiniteMenu extends Sprite{
  7.  
  8. private var level:int = -1;
  9.  
  10. public function InfiniteMenu(menuXml){
  11.  
  12. findSubs(menuXml.item);//pass in lowest level node called item
  13.  
  14. }
  15.  
  16. private function findSubs(subXml):void{
  17.  
  18. level++;
  19.  
  20. var numOfItems:int = subXml.length();
  21. for(var i:int = 0;i<numOfItems;i++){
  22. trace(level +subXml[i].@itemId);
  23. if(subXml[i].item.length() > 0)findSubs(subXml.item);//if there are children
  24. }
  25.  
  26. level--;
  27.  
  28. }
  29.  
  30. }
  31.  
  32. }

Report this snippet  

You need to login to post a comment.