Created
February 12, 2010 10:15
-
-
Save mmgj/302451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ctrloptcmd.utils { | |
/** | |
* XTrace.as | |
* | |
* @langversion : ActionScript 3.0 | |
* @playerversion : Flash 9.0 | |
* | |
* @author : Martin Jacobsen | |
* @since : 24-03-2009 | |
* @description : Hugely improved upon since last version. Now accepts .log() | |
* .info() .warn() and .error(). Will now display icons in console | |
* to alert about status. Will also show properties of objects | |
* (of datatype "Object") in console, but not (yet) in Flash output | |
* panel. | |
* When that's said and done; Usage is as before only now you have the | |
* possibility of using diferent levels of logging. W00t! | |
* | |
*/ | |
import flash.system.Capabilities; | |
import flash.external.ExternalInterface; | |
public class XTrace { | |
public static var ENABLED : Boolean = true; | |
private static var HAS_WARNED : Boolean = false; | |
public function XTrace(){ /*...*/ } | |
public static function log(...args) : void { | |
var logEntry : String = (args.length > 1) ? args.join(" | ") : args[0]; | |
XTrace.sendToConsole("console.log" , logEntry); | |
} | |
public static function info(...args) : void { | |
var logEntry : String= (args.length > 1) ? args.join(" | ") : args[0]; | |
XTrace.sendToConsole("console.info" , logEntry); | |
} | |
public static function warn(...args) : void { | |
var logEntry : String = (args.length > 1) ? args.join(" | ") : args[0]; | |
XTrace.sendToConsole("console.warn" , logEntry); | |
} | |
public static function error(...args) : void { | |
var logEntry : String = (args.length > 1) ? args.join(" | ") : args[0]; | |
XTrace.sendToConsole("console.error" , logEntry); | |
} | |
public static function sendToConsole(logLevel : String , str : * = "") : void { | |
if(ENABLED){ | |
switch (Capabilities.playerType) { | |
case "PlugIn": | |
case "ActiveX": | |
try { | |
ExternalInterface.call(logLevel, str); | |
} catch (e:Error) { | |
trace("Something went screwy: ", e.message) | |
} | |
break; | |
default : | |
trace(str); | |
break; | |
} | |
} else { | |
if(!HAS_WARNED) | |
trace("XTrace is disabled. Set XTrace.ENABLED to true to receive log messages.") | |
HAS_WARNED = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment