Friday, September 25, 2009

Koolmoves and the trace() statement

Getting Started
Unlike Flash, Koolmoves does not ship with an output panel to debug code. This can be corrected by installing the FlashLog Viewer from the KoolExchange. Once you have downloaded it you can pin it to your start menu for easy access. It works as a standalone viewer. You also need the debugger version of the Flash Player.

I have the latest debug Flash Player version installed for Mozilla Firefox and Koolmoves set to use the default browser rather than the native Internet Explorer. This can be set in Preferences/Player. You also need to set Firefox as the default browser on your computer.


The trace() statement
Once you are set up you can open your viewer as well as the Actionscript editor in Koolmoves. From author Derrick Ypenburg:


“The trace() statement will become your best friend in ActionScript development. Much of the ActionScript functionality you will create does not have a visual result on the stage, so it can be difficult to tell if your ActionScript is doing its job properly in the background. The trace() statement displays the results of your ActionScript as messages in the Output panel at runtime. The Output panel is also used to display loading errors and other non-ActionScript errors at runtime. You can also use the trace() statement to alert you when a task has begun and when it has completed.”

If one is to have a reasonable level of success with learning ActionScript in Koolmoves they will need this functionality. To see how this works, enter this code into the Action Script Editor:



In the Flash Log Viewer you should get a result that looks like this:





The first trace() statement is a String indicated by quotation marks. The statement will output anything in the quotation marks directly as written. In the second statement we have Numbers performing a math operation, and the trace() statement outputs the result of that operation.

You can also trace a variable as in:



We are are defining these two variables as Numbers and therefore we expect a Number in the result.
Place a zero after "num1"  to make it "num10" inside the trace() statement and it returns an error in the Flash Log Viewer:





When you get this result you know you need to go back and find the error and the Viewer tells you there is something wrong with var num10.  This shows how the trace() statement can be utilized in Koolmoves. As you continue to learn you will use this statement a lot. It also helps you see how the code you write works. Happy tracing.

1 comment:

  1. I use this often to check that a function is getting what I expect..

    For example:
    I have a function that responds to mouse event

    function doIt(e:MouseEvent){
    trace (e.target);
    }

    ReplyDelete