AS3 Recursive Function


/ Published in: ActionScript 3
Save to your folder(s)

Run through infinite xml child nodes.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.