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 />

package {<br />

import flash.display.MovieClip;<br />

import flash.media.StageWebView;<br />

import flash.geom.Rectangle;<br />

import flash.ev<strong>en</strong>ts.KeyboardEv<strong>en</strong>t;<br />

import flash.ui.Keyboard;<br />

}<br />

public class StageWebViewExample ext<strong>en</strong>ds MovieClip{<br />

}<br />

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

public function StageWebViewExample()<br />

{<br />

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

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

webView.loadURL( "http://www.adobe.com" );<br />

}<br />

Focus<br />

stage.addEv<strong>en</strong>tList<strong>en</strong>er( KeyboardEv<strong>en</strong>t.KEY_DOWN, onKey );<br />

private function onKey( ev<strong>en</strong>t:KeyboardEv<strong>en</strong>t ):void<br />

{<br />

if( ev<strong>en</strong>t.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )<br />

{<br />

trace("back");<br />

webView.historyBack();<br />

ev<strong>en</strong>t.prev<strong>en</strong>tDefault();<br />

}<br />

if( ev<strong>en</strong>t.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )<br />

{<br />

trace("forward");<br />

webView.historyForward();<br />

}<br />

}<br />

Ev<strong>en</strong> though it is not a display object, the StageWebView class contains members that allow you to manage the focus<br />

transitions into and out of the control.<br />

Wh<strong>en</strong> the StageWebView object gains focus, it dispatches a focusIn ev<strong>en</strong>t. You use this ev<strong>en</strong>t to manage the focus<br />

elem<strong>en</strong>ts in your application, if necessary.<br />

Wh<strong>en</strong> the StageWebView relinquishes the focus, it dispatches a focusOut ev<strong>en</strong>t. A StageWebView instance can<br />

relinquish focus wh<strong>en</strong> a user “tabs” past the first or last control on the web page using a device trackball or directional<br />

arrows. The direction property of the ev<strong>en</strong>t object lets you know whether the focus flow is rising up past the top of<br />

the page or down through the bottom of the page. Use this information to assign focus to the appropriate display object<br />

above or below the StageWebView.<br />

On iOS, focus cannot be set programmatically. StageWebView dispatches focusIn and focusOut ev<strong>en</strong>ts with the<br />

direction property of FocusEv<strong>en</strong>t set to none. If the user touches inside the StageWebView, the focusIn ev<strong>en</strong>t is<br />

dispatched. If the user touches outside the StageWebView, the focusOut ev<strong>en</strong>t is dispatched.<br />

Last updated 6/6/2012<br />

1027

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

Saved successfully!

Ooh no, something went wrong!