Packagecom.myflashlab.air.extensions.webView
Classpublic class RichWebView
InheritanceRichWebView Inheritance flash.events.EventDispatcher

Deprecated! use com.myflashlab.air.extensions.richWebView.RichWebView instead.

Copyright 2017, myflashlab. All rights reserved. More Extensions on http://www.myflashlabs.com/

Download .ane from: http://www.myflashlabs.com/product/rich-webview-ane-adobe-air-native-extension/

Make sure to take care of the permissions manually if you are targeting AIR SDK 24+: https://github.com/myflashlab/webView-ANE/#permissions

View the examples

See also

com.myflashlab.air.extensions.webView.RichWebViewEvent


Public Properties
 PropertyDefined By
  canGoBack : Boolean
[read-only] returns true if webView can go back in history
RichWebView
  canGoForward : Boolean
[read-only] returns true if webView can go forward in history
RichWebView
  contentHeight : int
[read-only] indicates the content height of your HTML content
RichWebView
  height : int
Indicates the height of the rich webview relative to the main stage
RichWebView
  isEmbeddedBrowserInitialized : Boolean
[read-only]
RichWebView
  maximumZoomScale : Number
iOS Only - indicates the maximumZoomScale
RichWebView
  minimumZoomScale : Number
iOS Only - indicates the minimumZoomScale
RichWebView
  os : String
[read-only] indicates the current OS which the app is running in.
RichWebView
  scrollX : int
[read-only] indicates the x position for the scroller
RichWebView
  scrollY : int
[read-only] indicates the y position for the scroller
RichWebView
  sdkVersion : int
[read-only] indicates the Android SDK version.
RichWebView
  visible : Boolean
[write-only] change the visibility of the webview. On Android, when the webview is present, it will hijack the device's back button.
RichWebView
  width : int
Indicates the width of the rich webview relative to the main stage
RichWebView
  x : int
Indicates the x position of the rich webview relative to the main stage
RichWebView
  y : int
Indicates the y position of the rich webview relative to the main stage
RichWebView
  zoomScale : Number
iOS Only - indicates the zoomScale for the wevView
RichWebView
Public Methods
 MethodDefined By
  
RichWebView($stage:Stage = null)
Initialize the extension and pass in the flash stage to it so it can calculate the correct dimensions for the webView rectangle.
RichWebView
  
addEventListener($type:String, $listener:Function, $useCapture:Boolean = false, $priority:int = 0, $useWeakReference:Boolean = false):void
[override]
RichWebView
  
callJS($msg:String):void
use this method to call Javascript functions.
RichWebView
  
clearCache($bool:Boolean):void
Android only - clears browsing cache.
RichWebView
  
Android only - clears history
RichWebView
  
Use this method to close the webView window.
RichWebView
  
dispose():void
to dispose the extension
RichWebView
  
RichWebView
  
filingScroll($x:int, $y:int):void
Animate the scroller to the specified x,y location.
RichWebView
  
goBack():void
if _ex.canGoBack is true, it will take the webview one page back
RichWebView
  
goForward():void
if _ex.canGoForward is true, it will take the webview one page forward
RichWebView
  
hide($value:Boolean):void
Hide the webview instance so it's not visible anymore.
RichWebView
  
RichWebView
  
RichWebView
  
isSupported():Boolean
indicates if the extension is supported on the running device or not.
RichWebView
  
Move the Air application to the back of the activity stack which will result in showing the Android's home menu.
RichWebView
  
openData($x:int, $y:int, $width:int, $height:int, $data:HtmlDataSettings):void
RichWebView
  
openEmbeddedBrowser($url:String):Boolean
RichWebView
  
openWebViewLocal($x:int, $y:int, $width:int, $height:int, $file:File):void
Use this method to open local html files on sdcard.
RichWebView
  
openWebViewURL($x:int, $y:int, $width:int, $height:int, $url:String):void
Use this method for loading online URLs
RichWebView
  
pageDown($bool:Boolean):Boolean
Call this method to move the scrollbar down.
RichWebView
  
pageUp($bool:Boolean):Boolean
Call this method to move the scrollbar up.
RichWebView
  
Android only - when going to background, call this method to save resources on your device.
RichWebView
  
reload():void
reloads the page.
RichWebView
  
removeEventListener($type:String, $listener:Function, $useCapture:Boolean = false):void
[override]
RichWebView
  
Call this method to request the extension for a screenshot of the whole webview.
RichWebView
  
Android only - if you had called pauseTimers() before going to background, you should call this method to reactivate your HTML content.
RichWebView
  
scrollBy($x:int, $y:int):void
move the scroller by the x,y amount
RichWebView
  
scrollTo($x:int, $y:int):void
move the scroller to the specified x,y location
RichWebView
  
setPosition($x:int, $y:int, $width:int, $height:int):void
RichWebView
  
setViewPort($rect:Rectangle):void
Use this method to resize and reposition the webView viewport at runtime.
RichWebView
  
Call this method only in RichWebViewEvent.PAGE_STARTING event to allow the process of loading the url
RichWebView
  
stopLoad():void
Call this method to stop loading the current page
RichWebView
  
zoomIn():Boolean
Use this method to zoom in to your HTML page.
RichWebView
  
zoomOut():Boolean
Use this method to zoom out from your HTML page.
RichWebView
Public Constants
 ConstantDefined By
  ANDROID : String = android
[static]
RichWebView
  EXTENSION_ID : String = com.myflashlab.air.extensions.webView
[static] Extension ID for this extension
RichWebView
  IOS : String = ios
[static]
RichWebView
  VERSION : String = 9.0.0
[static] current version number of this extension
RichWebView
Property Detail
canGoBackproperty
canGoBack:Boolean  [read-only]

returns true if webView can go back in history


Implementation
    public function get canGoBack():Boolean
canGoForwardproperty 
canGoForward:Boolean  [read-only]

returns true if webView can go forward in history


Implementation
    public function get canGoForward():Boolean
contentHeightproperty 
contentHeight:int  [read-only]

indicates the content height of your HTML content


Implementation
    public function get contentHeight():int
heightproperty 
height:int

Indicates the height of the rich webview relative to the main stage


Implementation
    public function get height():int
    public function set height(value:int):void
isEmbeddedBrowserInitializedproperty 
isEmbeddedBrowserInitialized:Boolean  [read-only]


Implementation
    public function get isEmbeddedBrowserInitialized():Boolean
maximumZoomScaleproperty 
maximumZoomScale:Number

iOS Only - indicates the maximumZoomScale


Implementation
    public function get maximumZoomScale():Number
    public function set maximumZoomScale(value:Number):void
minimumZoomScaleproperty 
minimumZoomScale:Number

iOS Only - indicates the minimumZoomScale


Implementation
    public function get minimumZoomScale():Number
    public function set minimumZoomScale(value:Number):void
osproperty 
os:String  [read-only]

indicates the current OS which the app is running in. it's either MyAR.ANDROID or MyAR.IOS


Implementation
    public function get os():String
scrollXproperty 
scrollX:int  [read-only]

indicates the x position for the scroller


Implementation
    public function get scrollX():int
scrollYproperty 
scrollY:int  [read-only]

indicates the y position for the scroller


Implementation
    public function get scrollY():int
sdkVersionproperty 
sdkVersion:int  [read-only]

indicates the Android SDK version. you will need this when you are writting your JS logic when dealing with FileSelect input fields. You should check if current device is running on Lollipop Android or above and make sure your JS matches that. Depending on your tasks, you may need to write your JS differently, so, make sure to search the web to be able to safely get the desired outcome on all Android versions.


Implementation
    public function get sdkVersion():int
visibleproperty 
visible:Boolean  [write-only]

change the visibility of the webview.

On Android, when the webview is present, it will hijack the device's back button. and you should listen to the RichWebViewEvent.BACK_CLICKED event to know when the device's back button is clicked. The same thing still happens when you're hidding the webview using this property or the hide() method.

In simple words, even if you are hidding the webview, it's still there and it's still hijacking the device's back button.


Implementation
    public function set visible(value:Boolean):void

See also

widthproperty 
width:int

Indicates the width of the rich webview relative to the main stage


Implementation
    public function get width():int
    public function set width(value:int):void
xproperty 
x:int

Indicates the x position of the rich webview relative to the main stage


Implementation
    public function get x():int
    public function set x(value:int):void
yproperty 
y:int

Indicates the y position of the rich webview relative to the main stage


Implementation
    public function get y():int
    public function set y(value:int):void
zoomScaleproperty 
zoomScale:Number

iOS Only - indicates the zoomScale for the wevView


Implementation
    public function get zoomScale():Number
    public function set zoomScale(value:Number):void
Constructor Detail
RichWebView()Constructor
public function RichWebView($stage:Stage = null)

Initialize the extension and pass in the flash stage to it so it can calculate the correct dimensions for the webView rectangle. the other settings in the constructor are now deprecated and you should use the RichWebViewSettings class to set the required settings for your RichWebView instance.

Parameters
$stage:Stage (default = null)

See also

Method Detail
addEventListener()method
override public function addEventListener($type:String, $listener:Function, $useCapture:Boolean = false, $priority:int = 0, $useWeakReference:Boolean = false):void

Parameters

$type:String
 
$listener:Function
 
$useCapture:Boolean (default = false)
 
$priority:int (default = 0)
 
$useWeakReference:Boolean (default = false)

callJS()method 
public function callJS($msg:String):void

use this method to call Javascript functions. for example if you have a function in your js like this:

		 function diplayAlert(msg)
		 {
		 		alert(msg);
		 }
		 
you can call it this way:
		 _ex.callJS("diplayAlert('a msg from flash!')");
		 

Parameters

$msg:String

clearCache()method 
public function clearCache($bool:Boolean):void

Android only - clears browsing cache.

Parameters

$bool:Boolean

clearHistory()method 
public function clearHistory():void

Android only - clears history

closeWebView()method 
public function closeWebView():void

Use this method to close the webView window.

dispose()method 
public function dispose():void

to dispose the extension

disposeEmbeddedBrowser()method 
public function disposeEmbeddedBrowser():void

filingScroll()method 
public function filingScroll($x:int, $y:int):void

Animate the scroller to the specified x,y location.

Parameters

$x:int
 
$y:int

See also

goBack()method 
public function goBack():void

if

_ex.canGoBack
is true, it will take the webview one page back

goForward()method 
public function goForward():void

if

_ex.canGoForward
is true, it will take the webview one page forward

hide()method 
public function hide($value:Boolean):void

Hide the webview instance so it's not visible anymore. you can make it visible again by passing false to this method.

On Android, when the webview is present, it will hijack the device's back button. and you should listen to the RichWebViewEvent.BACK_CLICKED event to know when the device's back button is clicked. The same thing still happens when you're hidding the webview using this method or the visible setter property.

In simple words, even if you are hidding the webview, it's still there and it's still hijacking the device's back button.

Parameters

$value:Boolean — visiblility value of the RichWebView

See also

initEmbeddedBrowser()method 
public function initEmbeddedBrowser():void

isEmbeddedBrowserSupported()method 
public function isEmbeddedBrowserSupported():Boolean

Returns
Boolean
isSupported()method 
public function isSupported():Boolean

indicates if the extension is supported on the running device or not. in iOS, the min SDK Version is 6.1

Returns
Boolean
moveAndroidTaskToBack()method 
public function moveAndroidTaskToBack():Boolean

Move the Air application to the back of the activity stack which will result in showing the Android's home menu.

Returns
Boolean — If the task was moved (or it was already at the back) true is returned, else false.
openData()method 
public function openData($x:int, $y:int, $width:int, $height:int, $data:HtmlDataSettings):void

Parameters

$x:int
 
$y:int
 
$width:int
 
$height:int
 
$data:HtmlDataSettings

openEmbeddedBrowser()method 
public function openEmbeddedBrowser($url:String):Boolean

Parameters

$url:String

Returns
Boolean
openWebViewLocal()method 
public function openWebViewLocal($x:int, $y:int, $width:int, $height:int, $file:File):void

Use this method to open local html files on sdcard.

Parameters

$x:int
 
$y:int
 
$width:int
 
$height:int
 
$file:File

openWebViewURL()method 
public function openWebViewURL($x:int, $y:int, $width:int, $height:int, $url:String):void

Use this method for loading online URLs

Parameters

$x:int
 
$y:int
 
$width:int
 
$height:int
 
$url:String

pageDown()method 
public function pageDown($bool:Boolean):Boolean

Call this method to move the scrollbar down. pass

true
and the page will go the whole way down otherwise it will go down only to the hight of the current view.

Parameters

$bool:Boolean

Returns
Boolean
pageUp()method 
public function pageUp($bool:Boolean):Boolean

Call this method to move the scrollbar up. pass

true
and the page will go the whole way up otherwise it will go up only to the hight of the current view.

Parameters

$bool:Boolean

Returns
Boolean
pauseTimers()method 
public function pauseTimers():void

Android only - when going to background, call this method to save resources on your device. it will pause all html5 processes or animation or timers.

See also

reload()method 
public function reload():void

reloads the page.

removeEventListener()method 
override public function removeEventListener($type:String, $listener:Function, $useCapture:Boolean = false):void

Parameters

$type:String
 
$listener:Function
 
$useCapture:Boolean (default = false)

requestBitmap()method 
public function requestBitmap():void

Call this method to request the extension for a screenshot of the whole webview. when the screenshot is ready, RichWebViewEvent.SCREENSHOT will be dispatched and you can access the BitmapData object in e.param

resumeTimers()method 
public function resumeTimers():void

Android only - if you had called pauseTimers() before going to background, you should call this method to reactivate your HTML content.

See also

scrollBy()method 
public function scrollBy($x:int, $y:int):void

move the scroller by the x,y amount

Parameters

$x:int
 
$y:int

scrollTo()method 
public function scrollTo($x:int, $y:int):void

move the scroller to the specified x,y location

Parameters

$x:int
 
$y:int

See also

setPosition()method 
public function setPosition($x:int, $y:int, $width:int, $height:int):void

Parameters

$x:int
 
$y:int
 
$width:int
 
$height:int

See also

setViewPort()method 
public function setViewPort($rect:Rectangle):void

Use this method to resize and reposition the webView viewport at runtime. Or you can use the x, y, width and height properties individually. but using this method to set all the properties in one call will be a bit more CPU friendly.

Parameters

$rect:Rectangle

shouldContinueLoadingTheURL()method 
public function shouldContinueLoadingTheURL():void

Call this method only in RichWebViewEvent.PAGE_STARTING event to allow the process of loading the url

stopLoad()method 
public function stopLoad():void

Call this method to stop loading the current page

zoomIn()method 
public function zoomIn():Boolean

Use this method to zoom in to your HTML page. on iOS, you may need to set

maximumZoomScale
and
minimumZoomScale
before trying to zoom.

Returns
Boolean
zoomOut()method 
public function zoomOut():Boolean

Use this method to zoom out from your HTML page. on iOS, you may need to set

maximumZoomScale
and
minimumZoomScale
before trying to zoom.

Returns
Boolean
Constant Detail
ANDROIDConstant
public static const ANDROID:String = android

EXTENSION_IDConstant 
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.webView

Extension ID for this extension

IOSConstant 
public static const IOS:String = ios

VERSIONConstant 
public static const VERSION:String = 9.0.0

current version number of this extension

Examples
Usage as follow
     import com.myflashlab.air.extensions.webView.
     
     var _ex:RichWebView = new RichWebView(this.stage);
     
     // indicates the Android SDK version. you will need this when you are writting your JS logic when dealing with FileSelect input fields.
     trace("Android SDK version: ", _ex.sdkVersion);
     
     // add listeners
     _ex.addEventListener(RichWebViewEvent.BACK_CLICKED, onBackClicked);
     _ex.addEventListener(RichWebViewEvent.PAGE_STARTED, onPageStarted);
     _ex.addEventListener(RichWebViewEvent.PAGE_PROGRESS, onPageProgress);
     _ex.addEventListener(RichWebViewEvent.PAGE_FINISHED, onPageFinished);
     _ex.addEventListener(RichWebViewEvent.RECEIVED_SSL_ERROR, onReceivedError);
     _ex.addEventListener(RichWebViewEvent.RECEIVED_MESSAGE_FROM_JS, onReceivedMessage);
     _ex.addEventListener(RichWebViewEvent.SCREENSHOT, onScreenshot);
     _ex.addEventListener(RichWebViewEvent.TOUCH, onTouch);
     
     // set optional RichWebview settings (apply these settings AFTER initializing the ANE and BEFORE opening a webpage)
     RichWebViewSettings.ENABLE_BITMAP_CAPTURE = true;
     RichWebViewSettings.ENABLE_COOKIES = true;
     RichWebViewSettings.ENABLE_THIRD_PARTY_COOKIES = true;
     RichWebViewSettings.ENABLE_GPS = true;
     RichWebViewSettings.ENABLE_ZOOM = true;
     RichWebViewSettings.ENABLE_SCROLL_BOUNCE = false;
     RichWebViewSettings.BG_COLOR_HEX = "#FFFFFFFF"; // AARRGGBB
     //RichWebViewSettings.USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36"; // useful when you are trying to load embedded YouTube or Vimeo videos
     RichWebViewSettings.ENABLE_AIR_PREFIX = true; // This property works on Android ONLY and is set to true by default.
     RichWebViewSettings.MEDIA_PLAYBACK_REQUIRES_USER_GESTURE = true;
     
     // you may load local html content from File.documentsDirectory or File.applicationStorageDirectory
     _ex.openWebViewLocal(0, 0, stage.stageWidth, stage.stageHeight, File.documentsDirectory.resolvePath("webview/index.html"));
     
     // or you may load an online url as follow
     //_ex.openWebViewURL(0, 0, stage.stageWidth, stage.stageHeight, "http://www.myflashlabs.com/");
     
     function onBackClicked(e:RichWebViewEvent):void
     {
         if (_ex.canGoBack) _ex.goBack();
         else _ex.closeWebView();
     }
     
     function onPageStarted(e:RichWebViewEvent):void
     {
         trace("page started to be loaded");
     }
     
     function onPageProgress(e:RichWebViewEvent):void
     {
         trace("page loading: " + e.param + "%");
     }
     
     function onPageFinished(e:RichWebViewEvent):void
     {
         trace("page load completed");
     }
     
     function onReceivedError(e:RichWebViewEvent):void
     {
         trace("error = " + e.param);
     }
     
     function onReceivedMessage(e:RichWebViewEvent):void
     {
         trace("onReceivedMessage: ", e.param);
     }
     
     function onScreenshot(e:RichWebViewEvent):void
     {
         var bm:Bitmap = new Bitmap(e.param, "auto", true);
         this.addChild(bm);
     }
     
     function onTouch(e:RichWebViewEvent):void
     {
         trace("onTouch > " + "x = " + e.param.x + " y = " + e.param.y);
     }