Packageflash.trace
Classpublic class Trace
InheritanceTrace Inheritance Object

Language Version : ActionScript 3.0
Runtime Versions : Flash Player 9, AIR 1.0

The Trace class allows to configure the AVM+ Debugger output.

With the Flash Player, you can enable the debugger output by editing the mm.cfg file with AS3Trace = 1.

With AIR you can package a mm.cfg file at the root of the app and by adding AS3Trace = 1 the app will create a flashlog.txt in the "app/Documents/Logs" directory, this file will contain the debugger output.

With the avmshell or the reshell, you can enable the debugger output with the arg option -Dastrace N where N is [1..4] (the level of logging).

View the examples



Public Methods
 MethodDefined By
 Inherited
_init():*
[static]
_init
  
getLevel(target:int):int
[static]
Trace
  
[static]
Trace
 Inherited
AS3
 Inherited
init():*
[static]
init
 Inherited
AS3
 Inherited
AS3
  
setLevel(l:int, target:int):*
[static]
Trace
  
[static] Register a listener to receive trace callbacks upon method and/or line number changes.
Trace
Protected Methods
 MethodDefined By
 Inherited
[static]
protected
 Inherited
_setPropertyIsEnumerable(o:*, V:String, enumerable:Boolean):void
[static]
protected
Public Constants
 ConstantDefined By
  FILE : * = 1
[static]
Trace
 Inheritedlength : int = 1
[static]
length
  LISTENER : * = 2
[static]
Trace
  METHODS : int = 1
[static] Logs method entry only.
Trace
  METHODS_AND_LINES : int = 3
[static] Logs method entry and line numbers.
Trace
  METHODS_AND_LINES_WITH_ARGS : int = 4
[static]
Trace
  METHODS_WITH_ARGS : int = 2
[static] Logs method entry and arguments.
Trace
  OFF : int = 0
[static] Turns off the logging.
Trace
Method Detail
getLevel()method
public static function getLevel(target:int):int

Parameters

target:int (default = NaN)

Returns
int
getListener()method 
public static function getListener():Function

Returns
Function
setLevel()method 
public static function setLevel(l:int, target:int):*

Parameters

l:int
 
target:int (default = NaN)

Returns
*
setListener()method 
public static function setListener(f:Function):*

Register a listener to receive trace callbacks upon method and/or line number changes. Passing null to this function effectively 'unregisters' the listener and only a single listener can be specified. The callback funcition must have the following signature:

             function foo(file_name:String, linenum:int, method_name:String, method_args:String):void
         
Depending upon the setting of the trace level, 2 or more arguments may be non-empty. In all cases file_name and method_name are obtained and passed to the callback. If the trace level include line numbers information then this value is also obtained and passed into the callback. Setting the trace level to include method arguments implies that the 'method_args' parameter will be filled with string representation of the arguments passed into the call.

Parameters

f:Function

Returns
*
Constant Detail
FILEConstant
public static const FILE:* = 1

LISTENERConstant 
public static const LISTENER:* = 2

METHODSConstant 
public static const METHODS:int = 1

Logs method entry only.

METHODS_AND_LINESConstant 
public static const METHODS_AND_LINES:int = 3

Logs method entry and line numbers.

METHODS_AND_LINES_WITH_ARGSConstant 
public static const METHODS_AND_LINES_WITH_ARGS:int = 4

METHODS_WITH_ARGSConstant 
public static const METHODS_WITH_ARGS:int = 2

Logs method entry and arguments.

OFFConstant 
public static const OFF:int = 0

Turns off the logging.

Examples
Basic Usage
     import flash.trace.Trace;
     
     //custom trace function
     function traceListener( file_name:String, linenum:int, method_name:String, method_args:String):void
     {
         trace( method_name + "( " + method_args.join( ", " ) + " )" );
     }
     
     //start the tracing
     Trace.setListener( traceListener );
     Trace.setLevel( Trace.METHODS_AND_LINES_WITH_ARGS, Trace.LISTENER );
     
     //more code here
     
     //stop the tracing
     Trace.setLevel( Trace.OFF, Trace.LISTENER );
     

Output format is AVMINF: LINE/MTHD.