View Full Version : Omit trace actions [via code?]
matt@macguffinandshemp.co
06-18-2007, 07:24 PM
Hi I was wondering if there was a bit of code that had the same effect as pressing the 'omit trace action' button in the publish menu.
What I'm looking to do is allow trace actions when the swf is published on one domain (used for testing) but omit them when it goes to the live server.
As I don't want to recompile after testing I was hoping someone knew of a trace on/off command that can be added to the AS.
Cheers
Matt
CyanBlue
06-18-2007, 07:54 PM
Howdy and Welcome... :)
The output from the trace() function is visible only within the Flash IDE... and there is no ActionScript that you can use to turn on/off the output...
Maybe I am missing what you are asking???
matt@macguffinandshemp.co
06-18-2007, 08:03 PM
Using flash player 9 debug you can see all the trace actions from any flash movie that's on the web. I want to see these on my test domain but don't want them visible to the general public when the swf goes live.
Cheers
Matt
CyanBlue
06-18-2007, 08:30 PM
Well... That's out of my league cuz I have not tried CS yet... Let me move the question to the right forum for you...
dr_zeus
06-18-2007, 09:54 PM
There is no way to do this via ActionScript. You must recompile your SWF.
kdittyr
06-19-2007, 07:20 PM
I always put a testing variable in my code, then an if statement that says if testing == 1 allow trace calls... This has to be done for every trace call in your code. I am sure there is a better work around, but it works very well for me. I have been doing this ever since I saw a plugin for firefox that could supposedly read the trace calls, though I don't remember what it was called. That could potentially be a huge security risk for many websites that I work on, this is my fix.
Once again:// testing variable for trace allowance
// if this is for release change to 0
var testing:Number = 1;
// code
// code
// code
// code
// then wherever a trace call might be
if(testing == 1){
trace("whatever it is I am tracing");
}
dr_zeus
06-19-2007, 07:56 PM
I have been doing this ever since I saw a plugin for firefox that could supposedly read the trace calls, though I don't remember what it was called. That could potentially be a huge security risk for many websites that I work on, this is my fix.
You're thinking of FlashTracer (https://addons.mozilla.org/en-US/firefox/addon/3469).
kdittyr
06-19-2007, 08:39 PM
That's the one, thanks :)
plutocrat
06-19-2007, 11:00 PM
To be honest, I think you are going about this the wrong way.
I use a Console class that lets me add, trace, store and manipulate my development output. Here is a small chunk of it that is pertinent here:
//Class:
package com.utils {
flash.utils.getTimer()
public class Cnsl {
public static var aCnsl:Array = new Array()
public static var isTracing:Boolean = true;
public static function t($:*):void {
aCnsl.push(getTimer()+" > "+$)
if (isTracing) trace(aCnsl[aCnsl.length-1])
}
}
}
//Implementation:
import com.utils.Cnsl
Cnsl.t("IN UR CONSOLE, TRACIN UR STUFF")
/* Output @ 4 secs into the program:
4000 > IN UR CONSOLE, TRACIN UR STUFF
*/
Note that as the traces are stored in an array, they can be used again, or traced "internally" using an in-application TextField. Further, Cnsl.t() can be accessed by the user if need be, thereby allowing for console input mid application.
Why the vry shrthnd? I use the class a lot, and so it is lame to have to write Console.addTracedVariableValueInHere(), rather than Cnsl.t() :)
Finally, you will note that if I want to turn off tracing, I can simply by calling Csnl.isTracing = false. Easy easy.
Hope that helps.
matt@macguffinandshemp.co
06-20-2007, 11:46 PM
I ended up adapting the bit-101 debug class to simply trace rather than send the messages to his console
http://www.bit-101.com/blog/?p=642
I now have a neat little class called 'de' so to trace I just type de.bug('arg') and I get arg= arg (saves on a bit of typing)
I've hooked this in to a _global variable that looks for certain key words, such as 'offline' or the test server domain. So I now can trace in my test environments and it shuts down when live.
Thanks for everyone's suggestions
jcodec
07-26-2007, 07:51 PM
I created a simple debugger class that allows you to externally set your desired debug level with an external configuration file. That way you can change your output level at will without recompiling the source code. Just change one number in a simple text file.
Essentially, the Debugger class works like this:
1. Import Debugger wherever you would need to use a trace action.
2. Call Debugger.init() early in your application to initialize it.
3. Debugger will load a text file called debug.txt which contains only the text debug=0, debug=1, debug=2, debug=3 or debug=4 (depending on the level of detail you want in your console output, see below).
4. instead of using trace, use Debugger.alert.
The method signature looks like this:public static function alert(message:Object):Void
The message object contains two elements, level (for how serious the message is) and msg (the string to actually trace). By having a "level" associated with the trace output you are able to filter your messages by severity. I use four levels of classification:
1. fatal errors
2. warnings
3. standard messages
4. verbose messages
Setting the debug level in debug.txt filters out any number higher than the debug level. For example, debug=2 will show fatal errors and warnings but not standard messages or verbose messages. debug=0 will show nothing and debug=4 will show everything.
As a bonus feature, you are also able to set the debug level internally at runtime with this simple method:public static function setOutputLevel(n:Number):Void
To reduce white noise, one trick I like to do with Debugger is to set debug=0 so I can concentrate on what I'm working on at the moment and use trace actions temporarily. With no output in the console at all temporary trace actions stand out like a shining beacon! Ultimately I remove my traces and replace them with Debugger alerts as I see fit.
The one caveat with using Debugger is that it does take time, though it is only a fraction of a second, to load and parse the debug text file. Therefore, to make sure Debugger is available at the very beginning of my application i make Debugger dispatch an event when it initializes. Since I use a custom event management system (see my tutorial on centralized event management here at actionscript.org - http://www.actionscript.org/resources/articles/610/1/Centralized-Event-Management-in-Actionscript-20/Page1.html ) I removed it from the source code below but it's a trivial matter to include one of your choosing.
Here's the source code for Debugger./**
* Debugger management class [0.1.0].
* Use this utility class instead of trace to globally manage debugging output.
*
* @class Debugger
* @author Jason Cook
* @version 0.1.0
*
* @history 0.1.0 (2007.02.08) Created initial version of Debugger.
*/
class Debugger {
/**
* The level of feedback the user provides to the user:
* 0: No feedback.
* 1: Errors only.
* 2: Errors and warnings (default).
* 3: Errors, warnings and messages.
* 4: Errors, warnings and verbose messages.
*/
private static var _outputLevel:Number;
/**
* Private empty constructor. This class cannot be instantiated.
*/
private function Debugger() {
}
public static function init():Void {
if (_outputLevel != undefined) return;
var lv:LoadVars = new LoadVars();
lv.onLoad = function(success:Boolean):Void {
if (success) {
Debugger.setOutputLevel(LoadVars(this).debug);
} else {
Debugger.setOutputLevel(2);
}
};
lv.load("debug.txt");
}
/**
* Static alert method. Traces messages of a certain severity to the output panel.
* @param message (Object) A debug message object with two parameters: level (the severity of the message) and msg (the string message).
*/
public static function alert(message:Object):Void {
if (_outputLevel >= message.level && _outputLevel != undefined) trace(message.msg);
}
/**
* Set the level of feedback the user provides to the user.
* @param n (Number) The output level to set Debugger to (0-4).
* @return Void
*/
public static function setOutputLevel(n:Number):Void {
var a:String = "off";
var b:String = "off";
var c:String = "off";
var d:String = "off";
var append:String = "";
switch(n) {
case 0 :
append = " ### WARNING [Debugger.setOutputLevel] Output level 0 will ignore potentially critical error messages."
break;
case 1 :
a = "on";
break;
case 2 :
a = "on";
b = "on";
break;
case 3 :
a = "on";
b = "on";
c = "on";
break;
case 4 :
a = "on";
b = "on";
c = "on";
a = "on";
append = " ### WARNING [Debugger.setOutputLevel] Output level 4 may have a negative impact on system performance."
default :
trace("### ERROR [Debugger.setOutputLevel] Invalid argument. Output level must be either 0, 1, 2, 3 or 4.");
return;
}
trace("[Debugger.setOutputLevel] Setting output level: ERRORS ("+a+"), WARNINGS ("+b+"), MESSAGES ("+c+"), VERBOSE MESSAGES ("+d+")."+append);
_outputLevel = n;
}
}Here is the content of debug.txtdebug=3
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.