# Handy Tip - myTrace() function

**URL:** <https://forum.kirupa.com/t/handy-tip-mytrace-function/295238>\
**Category:** flash\
**Created:** [August 27, 2009, 3:05am UTC](https://forum.kirupa.com/t/handy-tip-mytrace-function/295238 "2009-08-27T03:05:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MindSpace](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MindSpace](https://forum.kirupa.com/u/MindSpace)\
**Post date:** [August 27, 2009, 3:05am UTC](https://forum.kirupa.com/t/handy-tip-mytrace-function/295238/1 "2009-08-27T03:05:52Z")

</div>

This is something I’ve found handy over the years, so I thought I’d share it.

Essentially, I often create a function like myTrace(), as shown below. Then, instead of writing trace() calls, I write myTrace() calls.

Why? It gives me more control. I can, for example, choose to do nothing with all traces (ideal when compiling to release, to be sure people with debug players don’t see anything).  
Or only trace out essential traces.  
I can also redirect all traces to something like MonsterDebugger.  
Or redirect all traces to a textbox (handy when debugging on a non-coding machine).  
Or I can simply redirect all traces to trace() as if nothing had ever happened.

Example Code:

```auto
private function myTrace(traceString:String):void
{
	if (false) // Pass all traces through. // false = temporarily disabled.
		trace(traceString);
	if (traceString.indexOf("essential") != 0) // only trace messages containing "essential".
		trace(traceString);

	//MonsterDebugger.trace(this, traceString);
	
	/*if (true) { // redirect all traces to a textbox (created earlier)
		traceString += "
";
		serialOutput.text += traceString;
		serialOutput.verticalScrollPosition = serialOutput.maxVerticalScrollPosition;
	}*/

}

```
