15.2. Using the HTML Component

Unlike the Flex 2 TextArea component that allowed a limited subset of HTML tags, the AIR HTML component will display any compliant HTML content that runs in any modern browser. The HTML component can accept a basic HTML text string or can point to a local or external URL.

15.2.1. Basic HTML

To demonstrate how to load basic HTML, please create a new AIR project named Chapter15_HTML_Basic, which will create a new file named Chapter15_HTML_Basic.mxml. Listing 15-1 shows an example that includes a variable named htmlString that is some basic HTML code. It is set as [Bindable] and bound to the htmlText property of the HTML component. To test this, add the contents of Listing 15-1 to the Chapter15_HTML_Basic.mxml file, and then run the application. The results can be seen in Figure 15-1.

Example 15-1. An example of an HTML component with a basic HTML string
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
        <![CDATA[
        [Bindable]
        private var htmlString:String = '<html>' +
            '<body>' +
            '<p align="center"><font size="2" id="f1">' +
            'This is a paragraph with font size of 2 and aligned center. +
            '</font></para>' +
            '<p><font size="5" id="f2"><i>' +
            'This is paragraph with a font size of 5 and italics.' +
            '</i></font></p>' +
            '</body>' +
            '</html>' ]]> </mx:Script> <mx:HTML id="html" htmlText="{htmlString}" width="200" height="200" horizontalCenter="0" verticalCenter="0"/> </mx:WindowedApplication> ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.