deepTrace
deepTrace for flash9/10
deepTrace any displayObject, and add optional fields to trace
deepTrace will trace the object and all it's children.
import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.Error; public static function deepTrace( obj:DisplayObject, ?fields:Array<String>, level:Int = 0 ):Void { var tabs:String = ""; var i:Int = 0; var l:Int = level; for ( i in 0...l){ tabs += "\t"; } var printData = function(newField, fieldString) { return fieldString + (fieldString != "" ? "; " : "") +newField+ " : " +Reflect.field(obj, newField); } if(fields != null && fields.length > 0){ try{ trace(tabs + obj + " -> ( " + Lambda.fold(fields, printData, "") + " )"); }catch(e:Error){ trace(tabs + obj + " -> ( has no fields ["+fields+"] )"); } } if(Std.is(obj,DisplayObjectContainer)){ for ( i in 0...Reflect.field(obj, "numChildren") ){ deepTrace( Reflect.field(obj, "getChildAt")(i), fields, level + 1 ); } } }
deepTrace(myObject,["x","y"]);
will trace something like
[object myObject] -> ( x : 560; y : 150 ) [object MovieClip] -> ( x : 0; y : -50 ) [object Shape] -> ( x : 0; y : 0 ) [object Shape] -> ( x : 0; y : 0 ) [object Sprite] -> ( x : 200; y : 100 ) [object Sprite] -> ( x : 100 ; y : 300 ) [object SimpleButton] -> ( x : -10 ; y : 100 ) [object TextField] -> ( x : -40 ; y : -30 ) [object Sprite] -> ( x : 300 ; y : 300 ) [object SimpleButton] -> ( x : -10 ; y : 100 ) [object TextField] -> ( x : -40 ; y : -30 ) [object Sprite] -> ( x : 200 ; y : 300 ) [object CustomButton] -> ( x : -37 ; y : 100 ) [object Shape] -> ( x : 0; y : 0 ) [object TextField] -> ( x : 0 ; y : 0 )
version #6826, modified 2009-08-19 22:15:46 by theRemix