13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 59: Programming HTML and<br />

JavaScript in AIR<br />

Adobe AIR 1.0 and later<br />

A number of programming topics are unique to developing Adobe® AIR® applications with HTML and JavaScript. The<br />

following information is important whether you are programming an HTML-based AIR application or programming<br />

a SWF-based AIR application that runs HTML and JavaScript using the HTMLLoader class (or mx:HTML Flex<br />

compon<strong>en</strong>t).<br />

About the HTMLLoader class<br />

Adobe AIR 1.0 and later<br />

The HTMLLoader class of Adobe AIR defines the display object that can display HTML cont<strong>en</strong>t in an AIR application.<br />

SWF-based applications can add an HTMLLoader control to an existing window or create an HTML window that<br />

automatically contains a HTMLLoader object with HTMLLoader.createRootWindow(). The HTMLLoader object<br />

can be accessed through the JavaScript window.htmlLoader property from within the loaded HTML page.<br />

Loading HTML cont<strong>en</strong>t from a URL<br />

Adobe AIR 1.0 and later<br />

The following code loads a URL into an HTMLLoader object (add the HTMLLoader as a child of the stage or other<br />

display object container to display the HTML cont<strong>en</strong>t in your application):<br />

import flash.html.HTMLLoader;<br />

var html:HTMLLoader = new HTMLLoader;<br />

html.width = 400;<br />

html.height = 600;<br />

var urlReq:URLRequest = new URLRequest("http://www.adobe.com/");<br />

html.load(urlReq);<br />

An HTMLLoader object's width and height properties are both set to 0 by default. You will want to set these<br />

dim<strong>en</strong>sions wh<strong>en</strong> adding an HTMLLoader object to the stage. The HTMLLoader dispatches several ev<strong>en</strong>ts as a page<br />

loads. You can use these ev<strong>en</strong>ts to determine wh<strong>en</strong> it is safe to interact with the loaded page. These ev<strong>en</strong>ts are described<br />

in “Handling HTML-related ev<strong>en</strong>ts in AIR” on page 1017.<br />

Note: In the Flex framework, only classes that ext<strong>en</strong>d the UICompon<strong>en</strong>t class can be added as childr<strong>en</strong> of a Flex Container<br />

compon<strong>en</strong>ts. For this reason, you cannot directly add an HTMLLoader as a child of a Flex Container compon<strong>en</strong>t;<br />

however you can use the Flex mx:HTML control, you can build a custom class that ext<strong>en</strong>ds UICompon<strong>en</strong>t and contains<br />

an HTMLLoader as a child of the UICompon<strong>en</strong>t, or you can add the HTMLLoader as a child of a UICompon<strong>en</strong>t and add<br />

the UICompon<strong>en</strong>t to the Flex container.<br />

Last updated 6/6/2012<br />

978

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!