Previous Page Next Page

3.6. Troubleshooting AIR Applications

The process of developing an AIR application is much the same as that of developing an HTML-based web application.

The same thing is true when it comes to debugging an AIR application. One difference is that the JavaScript error messages go to the console (when running the application with AIR Debug Launcher) and not in a separate window as you might be used to in the browser world.

This section covers some of the new messages you might come across that are introduced by the runtime and also gives you a quick overview of an AIR SDK tool that can be used to make your life easier when working with HTML/JavaScript.

3.6.1. New JavaScript error messages

3.6.1.1. Security violation for Javascript code

If you call code that is restricted from use in the application sandbox due to security restrictions, the runtime dispatches a JavaScript error: "Adobe AIR runtime security violation for JavaScript code in the application security sandbox."

3.6.1.2. Referencing a JavaScript object no longer available

When an object dispatches an event to a handler that has already been unloaded, you see the following error message: "The application attempted to reference a JavaScript object in an HTML page that is no longer loaded."

To avoid this error, remove JavaScript event listeners in an HTML page before it goes away. In the case of page navigation (within an HTMLLoader object), remove the event listener during the unload event of the window object.

// In this example the event listener for an uncaughtScript
Exception event is removed when unload event fires
window.onunload = cleanup;
window.htmlLoader.addEventListener('uncaughtScriptException',
uncaughtScriptException);
function cleanup()
{
    window.htmlLoader.removeEventListener('uncaught
ScriptException',
 uncaughtScriptExceptionHandler);
}

3.6.1.3. Missing event listeners for error events

Exceptions, rather than events, are the primary mechanism for error handling in the runtime classes. However, because exceptions don't work for asynchronous operations, the runtime dispatches an error event object.

If you do not create a listener for the error event (such as when loading files asynchronously), the AIR Debug Launcher presents a dialog box with information about the error.

Most error events are based on the ErrorEvent class, and have a property named text that is used to store a descriptive error message.

An error event does not cause an application to stop executing. It manifests only as a dialog box when launched via ADL and is not presented when running in an installed application.

3.6.2. AIR Introspector

The Adobe AIR SDK includes a JavaScript based tool called AIR Introspector that makes it easier to develop HTML based applications for Adobe AIR. Tje tool can be used to introspect the content (such as the DOM) of HTML content running within an AIR application.

Figure 3-2. AIR Introspector window


In order to use the AIR Introspector with your application, copy the AIRIntrospector.js file from the frameworks directory of the SDK into to your application project directory and then load the file into your application via the script tag:

<script src="airintrospector.js" type="text/javascript">
</script>

The tool provides a number of features and functionality:

At this point, you should have a good understanding of the HTML and JavaScript environments within Adobe AIR, as well as how to leverage AIR, Flash Player and third-party ActionScript 3 APIs directly from JavaScript.

The rest of the book will use this knowledge to show how to accomplish specific tasks from HTML and JavaScript applications running within Adobe AIR.

Previous Page Next Page