Outputting trace to both Browser & Debugger in ActionScript 3Tags: as3, flash — 10th of July 2010

Why?

Because you want to quickly see all your debuging information in browser and ide. And you really don't want to install the Debugging version of Flash.

Code

Treat the code just like trace
trace("Hi ", "123");
Debug.Log("Hi ", "123");
package
{
	import flash.external.ExternalInterface;
	import flash.system.Capabilities;

	
	/**
	 * Allows you to output log to both Browser & IDE.
	 * Helpful when you want to execute "trace" onto the browser
	 * @author Pavel
	 */
	public class Debug
	{
		public static function Log(...rest)
		{
			var log:String = "";
			for (var i:uint = 0; i < rest.length; i++)
			{
				log += String(rest[i]);
			}
			
			if (Capabilities.isDebugger)
			{
				trace(log);
			}
			else
			{
				ExternalInterface.call("console.log", log);
			}
		}
	}
}