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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Programming HTML and JavaScript in AIR<br />

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

html.width = 300;<br />

html.height = 300;<br />

html.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, completeHandler);<br />

var xhtml:XML =<br />

<br />

<br />

foo = 333;<br />

function test() {<br />

return "OK.";<br />

}<br />

<br />

<br />

Hi.<br />

<br />

;<br />

html.loadString(xhtml.toString());<br />

function completeHandler(e:Ev<strong>en</strong>t):void {<br />

trace(html.window.foo); // 333<br />

trace(html.window.docum<strong>en</strong>t.getElem<strong>en</strong>tById("p1").innerHTML); // Hi.<br />

trace(html.window.test()); // OK.<br />

}<br />

To access the cont<strong>en</strong>t of an HTML elem<strong>en</strong>t, use the innerHTML property. For example, the previous code uses<br />

html.window.docum<strong>en</strong>t.getElem<strong>en</strong>tById("p1").innerHTML to get the cont<strong>en</strong>ts of the HTML elem<strong>en</strong>t named p1.<br />

You can also set properties of the HTML page from ActionScript. For example, the following example sets the cont<strong>en</strong>ts<br />

of the p1 elem<strong>en</strong>t and the value of the foo JavaScript variable on the page using a refer<strong>en</strong>ce to the containing<br />

HTMLLoader object:<br />

html.window.docum<strong>en</strong>t.getElem<strong>en</strong>tById("p1").innerHTML = "Goodbye";<br />

html.window.foo = 66;<br />

Embedding SWF cont<strong>en</strong>t in HTML<br />

Adobe AIR 1.0 and later<br />

You can embed SWF cont<strong>en</strong>t in HTML cont<strong>en</strong>t within an AIR application just as you would in a browser. Embed the<br />

SWF cont<strong>en</strong>t using an object tag, an embed tag, or both.<br />

Note: A common web developm<strong>en</strong>t practice is to use both an object tag and an embed tag to display SWF cont<strong>en</strong>t in an<br />

HTML page. This practice has no b<strong>en</strong>efit in AIR. You can use the W3C-standard object tag by itself in cont<strong>en</strong>t to be<br />

displayed in AIR. At the same time, you can continue to use the object and embed tags together, if necessary, for HTML<br />

cont<strong>en</strong>t that is also displayed in a browser.<br />

If you have <strong>en</strong>abled transpar<strong>en</strong>cy in the NativeWindow object displaying the HTML and SWF cont<strong>en</strong>t, th<strong>en</strong> AIR does<br />

not display the SWF cont<strong>en</strong>t wh<strong>en</strong> window mode (wmode) used to embed the cont<strong>en</strong>t is set to the value: window. To<br />

display SWF cont<strong>en</strong>t in an HTML page of a transpar<strong>en</strong>t window, set the wmode parameter to opaque or transpar<strong>en</strong>t.<br />

The window is the default value for wmode, so if you do not specify a value, your cont<strong>en</strong>t may not be displayed.<br />

Last updated 6/6/2012<br />

989

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

Saved successfully!

Ooh no, something went wrong!