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.

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

Displaying HTML cont<strong>en</strong>t in mobile apps<br />

JavaScript URI<br />

You can use a JavaScript URI to call a function defined in the HTML page that is loaded by a StageWebView object.<br />

The function you call using the JavaScript URI runs in the context of the loaded web page. The following example uses<br />

a StageWebView object to call a JavaScript function:<br />

package {<br />

import flash.display.*;<br />

import flash.geom.Rectangle;<br />

import flash.media.StageWebView;<br />

public class WebView ext<strong>en</strong>ds Sprite<br />

{<br />

public var webView:StageWebView = new StageWebView();<br />

public function WebView()<br />

{<br />

var htmlString:String = "" +<br />

"" +<br />

"function callURI(){" +<br />

"alert(\"You clicked me!!\");"+<br />

"}" +<br />

"Click Me" +<br />

"";<br />

webView.stage = this.stage;<br />

webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight );<br />

webView.loadString( htmlString );<br />

}<br />

}<br />

}<br />

More Help topics<br />

Sean Vois<strong>en</strong>: Making the Most of StageWebView<br />

Navigation ev<strong>en</strong>ts<br />

Wh<strong>en</strong> a user clicks a link in the HTML, the StageWebView object dispatches a locationChanging ev<strong>en</strong>t. You can call<br />

the prev<strong>en</strong>tDefault() method of the ev<strong>en</strong>t object to stop the navigation. Otherwise, the StageWebView object<br />

navigates to the new page and dispatches a locationChange ev<strong>en</strong>t. Wh<strong>en</strong> the page load has finished, the<br />

StageWebView dispatches a complete ev<strong>en</strong>t.<br />

A locationChanging ev<strong>en</strong>t is dispatched on every HTML redirect. The locationChange and complete ev<strong>en</strong>ts are<br />

dispatched at the appropriate time.<br />

On iOS, a locationChanging ev<strong>en</strong>t is dispatched before a locationChange ev<strong>en</strong>t, except for the first loadURL() or<br />

loadString() methods. A locationChange ev<strong>en</strong>t is also dispatched for navigational changes through iFrames and<br />

Frames.<br />

The following example illustrates how you can prev<strong>en</strong>t a location change and op<strong>en</strong> the new page in the system browser<br />

instead.<br />

Last updated 6/6/2012<br />

1025

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

Saved successfully!

Ooh no, something went wrong!