ActionScript 2.0 用のダンプ関数がWEB上にあまりなかったので作成
// function _dump // Version 0.4 function _dump(data,indent:Number){ if (! indent){indent=0;} if (indent==0){ trace('------------------------- ↓'); } var space:String = ''; for (var key:String in data) { var value = data[key]; if ( typeof(value) == "object" ){ space = ''; for( var i:Number=0; i<indent*8; i++){ space += ' '; } trace( space +key+' : ('+typeof(value)+') : '+value); indent++; _dump(value,indent); indent --; } else{ space = ''; for( var i:Number=0;i<indent*8;i++){ space += ' '; } trace( space +key+' : ('+typeof(value)+') : '+value); } } if ( typeof(data) == 'string' || typeof(data) == 'number' || typeof(data) == 'boolean' || typeof(data) == 'undefined' || typeof(data) == 'null' ){ trace( '名無し'+' : ('+typeof(data)+') : '+data); } if (indent==0){ trace('------------------------- ↑'+"\n"); } }
使い方は
var obj:Object = {x:1, y: "aaa", z: {foo: [1,2,3], bar: {a: 11, b: null, c: true}}}; _dump(obj);
出力結果
------------------------- ↓ x : (number) : 1 y : (string) : aaa z : (object) : [object Object] foo : (object) : 1,2,3 2 : (number) : 3 1 : (number) : 2 0 : (number) : 1 bar : (object) : [object Object] a : (number) : 11 b : (null) : null c : (boolean) : true ------------------------- ↑
不具合などありましたらコメント欄から是非ご指摘くださいませ。
ActionScript 3.0用はこちらにありました。(こちらの方が見やすくていいかも)
http://kjirou.sakura.ne.jp/mt/2007/10/as3_1.html
こちらもAS3用
http://www.libspark.org/wiki/dealforest/Dumper