Navigation

Previous

Archives

2007年11月19日 @ 10:21

Using the HTMLControl Class in Adobe AIR to parse

Using the HTMLControl Class in Adobe AIR to parse HTML as a data source

mikechambers November 9th, 2007

One of the cool features of Adobe AIR (especially for Flash developers) is its ability to render full featured HTML within Flash content. The rendering is handled by the WebKit core, and the HTML content can be from both local and remote URLs as well as from a string of HTML text.

HTML rendering within Flash content is handled by the ActionScript HTMLControl class (which is wrapped by the HTML component in Flex). The HTMLControl class is a DisplayObject instance (it directly inherits from Sprite) and thus renders its HTML directly to the display list.

However, it is possible to load HTML content into an HTMLControl instance, without placing it on the display list to be displayed. HTML content is still loaded and executed, and its DOM is exposed to the scripting environment. This means that you can essentially use the HTMLControl to load and parse HTML with the sole purpose of retrieving data from the HTML… i.e. using the HTMLControl you can treat HTML as a data source, as if it was XML.

This is done by leveraging the JavaScript APIs within HTML for manipulating the HTML DOM.

Below is a simple example that loads some HTML, and then uses various JavaScript DOM APIs to extract data and information from the HTML. Note that the HTML is never displayed or rendered to the screen.

2007年9月28日 @ 14:50

HTMLStyle

HTMLStyle 11Apr07 | 11



This is a component I developed for the sake of simplifying the process of formatting html-text in Flex.

Check it out:
Demo
Source
Documentation

HTMLStyle works pretty much the same as the tag and is also applicable in Actionscript code. Used in mxml this is the simplest form of how the component can be used:

Actionscript:

  1. <local:HMTLStyle id="myHTMLStyle">
  2.   <![CDATA[
  3.     .someStyleClass { color: #FF0000; }
  4.   ]]>
  5. </local:HMTLStyle>
  6.  
  7. <mx:TextArea styleSheet="{myHTMLStyle.styleSheet}" />

Page:[«]1[»]

Categories

Lately left messages

Comments

Linkage

Misc