Inspecting an object in the Console tab

The Console class defines five methods: log(), warn(), info(), error(), and dump().

The log(), warn(), info(), and error() methods all let you send an object to the Console tab. The most basic of these methods is the log() method. The following code sends a simple object, represented by the test variable, to the Console tab:

 var test = "hello"; 
 air.Introspector.Console.log(test);

However, it is more useful to send a complex object to the Console tab. For example, the following HTML page includes a button (btn1) that calls a function that sends the button object itself to the Console tab:

 <html> 
     <head> 
         <title>Source Viewer Sample</title> 
         <script type="text/javascript" src="scripts/AIRIntrospector.js"></script> 
         <script type="text/javascript"> 
             function logBtn() 
             { 
                 var button1 = document.getElementById("btn1"); 
                 air.Introspector.Console.log(button1); 
             } 
         </script> 
     </head> 
     <body> 
         <p>Click to view the button object in the Console.</p> 
         <input type="button" id="btn1" 
             onclick="logBtn()"  
             value="Log" /> 
     </body> 
 </html>

When you click the button, the Console tab displays the btn1 object, and you can expand the tree view of the object to inspect its properties:

You can edit a property of the object by clicking the listing to the right of the property name and modifying the text listing.

The info(), error(), and warn() methods are like the log() method. However, when you call these methods, the Console displays an icon at the beginning of the line:

Method

Icon

info()



error()



warn()



The log(), warn(), info(), and error() methods send a reference only to an actual object, so the properties available are the ones at the moment of viewing. If you want to serialize the actual object, use the dump() method. The method has two parameters:

Parameter

Description

dumpObject

The object to be serialized.

levels

The maximum number of levels to be examined in the object tree (in addition to the root level). The default value is 1 (meaning that one level beyond the root level of the tree is shown). This parameter is optional.

Calling the dump() method serializes an object before sending it to the Console tab, so that you cannot edit the objects properties. For example, consider the following code:

 var testObject = new Object(); 
 testObject.foo = "foo"; 
 testObject.bar = 234; 
 air.Introspector.Console.dump(testObject);

When you execute this code, the Console displays the testObject object and its properties, but you cannot edit the property values in the Console.

Adobe logo

Sign in to your account