Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

38 | Chapter 2: Getting Started with AIR Development


Adobe AIR provides a function to make it possible to send
information from the application to standard out at runtime.


runtime.trace


As we touched on earlier in the chapter, Adobe AIR provides
a mechanism for sending Strings from JavaScript to the com-
mand line.


Thetracefunction on theruntimeproperty takes a string,
which will then be output to ADL’s standard out. Here is an
example of its usage:


runtime.trace("This will be sent to standard out");

This can be useful for tracking information about the state of
the application without having to interrupt the execution of
the program.


Any non-String objects passed to trace will have their
toString( )function called. The JavaScriptObjectobject pro-
vides a defaulttoString( )implementation, although some
classes (such as Array) implement more context-sensitive
toString( ) functions.


Here is an example of tracing an Array that contains various
data types:


var a = ["a", 1, {foo:"bar"}];
runtime.trace(a);

This will result in the following output on the command line
from ADL:


a,1,[object Object]

Of course, you can implement your owntoString( )method
on your custom JavaScript classes, or overridetoString( )
functions on existing classes in order to provide more class-
specific output.

Free download pdf