« How to receive data in response to a file upload in Flex | Main | Using the Loader class to load and set dimensions of an image from the remote server in Flex 3 »

Creating and accessing JavaScript objects from ActionScript classes in AIR

These days I'm working on the O'Reilly AIR Cookbook creating the examples for the chapter on the HTMLLoader class.
The HTMLLoader class has a powerful method that lets you to load html content from a simple html string. The method is part of the public methods of the HTMLLoader class: loadString().
It accepts a parameter that contains the html content to load within an istance of the HTMLLoader class.

With this simple code you'll load the htmlToLoad string into the HTMLLoader class. The _html istance will render as HTML the content through the WebKit engine.

NOTE: Due to formatting problem I've posted the code examples and the ActionScript 3 class for this post on my personal blog :
Creating JavaScript functions within an ActionScript class in AIR

The cool thing is that you can use this approach to write JavaScript objects, functions and properties as well as defining the HTML structure within an ActionScript class, and then access to the html DOM via ActionScript code.

In the next page I've created an example where an HTML content is created within an ActionScript class and then loaded into an HTMLLoader object. I've accessed using ActionScript to the HTML DOM to get the content within the DIV tag.

Consider these three important considerations:
a) access to the DOM elements and JavaScript objects only after the page load event is dispatched. The page load event corresponds to the COMPLETE event dispatched by the HTMLLoader class. You can create an event listener for this event using the addEventListener() method:

_html.addEventListener(Event.COMPLETE, onComplete);

b) you can access to DOM elements using the window.document object and invoking the getElementById, and getElementsByTagNamer() methods. The window object represents the global JavaScript object for the content loaded into the HTML control.
c) you can edit and create the content of the html content using the innerText and innerHTML properties

NOTE: Due to formatting problem I've posted the code examples and the ActionScript 3 class for this post on my personal blog :

Creating JavaScript functions within an ActionScript class in AIR

TrackBack

TrackBack URL for this entry:
http://blog.comtaste.com/mt-tb.cgi/57

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on June 20, 2008 5:29 PM.

The previous post in this blog was How to receive data in response to a file upload in Flex.

The next post in this blog is Using the Loader class to load and set dimensions of an image from the remote server in Flex 3 .

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33