Saturday, July 6, 2013

ActionScript 3 Search through the display list for something

Search through the display list and return the first movie clip with this name. it helps if your names are all unique. public function getElementById( n:String, c:DisplayObjectContainer = null ) : DisplayObject { if( c == null ) { c = target; } var returnValue:DisplayObject; if( c.name == n ){ returnValue = target; }else{ if( c.getChildByName( n ) ) { returnValue = c.getChildByName( n ); } else{ loop( n, c ); } } function loop( id:String, container:DisplayObjectContainer ) : * { for (var i:uint=0; i const child:* = container.getChildAt(i); if( container.getChildAt(i) is DisplayObjectContainer ) { if( child.getChildByName( id ) ){ returnValue = child.getChildByName( id ); break; } else{ loop( id, DisplayObjectContainer(child) ); } } } } return returnValue;}Search through the display list and return the object. - Full Post

No comments:

Post a Comment