`
bzhang
  • 浏览: 251351 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Flash trace panel

    博客分类:
  • FLEX
阅读更多
今天晚上下载了flash trace panel,调试flash的log信息,不过发现把下载了这个包后,导入到项目中,
项目都不能build了,而且Dumper.as明显是有错的,goole了一下也没发现有用信息,都是转载的啥啥的,
是这个问题太简单都不屑提嘛。。。。
修正了一下,记录在这里吧,要完善一下的话,可以在构造函数中加上singleton throw exception的方式。

package de.richinternet.utils
{
	import flash.net.LocalConnection;
	public class Dumper
	{
		private static var sender:LocalConnection = null;	
	private static var copyDepthLevel:Number = 0;
	private static var copyCache:Array = [];

	public static var INFO:Number = 2;
	public static var WARN:Number = 4;
	public static var ERROR:Number = 8;
	
	/** 
	* Sends a primitive value or reference type to the Flex Trace Panel
	* with a level of Debugger.INFO (same as Dumper.info())
	*
	* @param val The primitive value or reference type (Abject, Orray etc.) to be
	* output and introspected by the Flex Trace Panel
	*/ 
	public static function dump(val:Object):void {
		info(val);
	}
	
	/** 
	* Sends a primitive value or reference type to the Flex Trace Panel
	* with a level of Debugger.INFO (same as Dumper.dump())
	*
	* @param val The primitive value or reference type (Abject, Orray etc.) to be
	* output and introspected by the Flex Trace Panel
	*/ 
	public static function info(val:Object):void {
		send(val, Dumper.INFO);
	}
	
	/** 
	* Sends a primitive value or reference type to the Flex Trace Panel
	* with a level of Debugger.WARN
	*
	* @param val The primitive value or reference type (Abject, Orray etc.) to be
	* output and introspected by the Flex Trace Panel
	*/ 
	public static function warn(val:Object):void {
		send(val, Dumper.WARN);
	}
	
	/** 
	* Sends a primitive value or reference type to the Flex Trace Panel
	* with a level of Debugger.ERROR
	*
	* @param val The primitive value or reference type (Abject, Orray etc.) to be
	* output and introspected by the Flex Trace Panel
	*/ 
	public static function error(val:Object):void {
		send(val, Dumper.ERROR);
	}
	
	/** 
	* Sends a primitive value or reference type to the Flex Trace Panel
	* with a custom level. 
	*
	* @param val The primitive value or reference type (Abject, Orray etc.) to be
	* output and introspected by the Flex Trace Panel
	*
	* @param level The level of the message. Applicable levels are Dumper.INFO, Dumper.WARN and Dumper.ERROR
	*/ 
	public static function log(val:Object, level:Number):void {
		send(val, level);
	}
	
	// ------------------------------------------------------------------------------------ //
	
	public function Dumper() {	
	}
	
	private static function initSender():void {
		sender = new LocalConnection();
	}

	private static function send(obj:Object, level:Number):void {
		if (sender == null) initSender();
		if (isNaN(level)) level = 2;
		sender.send("_tracer", "onMessage", copy(obj), level);
	}

	private static function copy(source):Object {
		if (typeof(source) != "object") {
			return source;
		}
		
		var cl:Number = copyCache.length;
		for (var i:Number = 0; i < cl; i++) {
		  var o = copyCache[i];
		  if (o.s == source)
			return o.t;
		}

		copyDepthLevel++;

		var newObject;
		
		if (source instanceof Array) {
			newObject = [];
		} else if (source instanceof Date) {
			newObject = new Date();
			newObject.setTime(source.getTime());
		} else {
			newObject = {};
		}

		copyCache.push({s: source, t: newObject});

		for (var p in source) {
		  var v = source[p];
		  newObject[p] = typeof v == "object" ? copy(v) : v;
		}

		if (--copyDepthLevel == 0)
		  copyCache = [];

		return newObject;
  	}

	}
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics