Intercepting Hyperlinks in HTML Component of Adobe AIR

BY
AIR’s HTML control provides an easy way to render complex html content. It also gives user flexibility in manipulating events and data it contains. For instance, one can easily react to a hyperlink click in an html document.
Consider the following html snippet:

 

var str:String = ‘Go to <a href=”google.com” id=”linkGoogle”>google</a>’;
html.data = str; // html is of type HTML…

When a user clicks on “google” link, by default, the HTML control will navigate away from the current page and go to google.com. Let’s assume that we’d like to do something different. Let’s say we want to display a native AIR dialog box (called GoogleDialog) that has a text field to accept keywords to search, Search button and Cancel button.
To achieve that, we need to capture the click event of that hyperlink and handle it accordingly.

 


var link:Object = html.htmlLoader.window.document.getElementById(“linkGoogle”);
if (link!=null)
link.addEventListener(“click”, clickHandler);

/**
 * Called when the link is clicked.
 */
private function clickHandler(obj:Object):void {
var googleDialog:GoogleDialog = new GoogleDialog();

}

It’s that simple.

Leave a Reply

Your email address will not be published. Required fields are marked

Your comment

Your name, please

Your email, please

POSTED

January 26, 2009

SHARE POST

LOCATED IN

(62)

CATEGORIES

HAVE A QUESTION ABOUT OUR SERVICES?

Ready to start on a project?

WANT TO SEE OUR WORK?

Visit our case studies page or request specific project examples.