Skip to content

Instantly share code, notes, and snippets.

View darkredz's full-sized avatar

Leng Sheng Hong darkredz

View GitHub Profile
@darkredz
darkredz / gist:3116153
Created July 15, 2012 10:07
UIWebView Native Extension Example
var nativeWeb:UIWebView = new UIWebView();
nativeWeb.stage = stage;
nativeWeb.viewPort = new Rectangle(0, 0, 600, 400);
nativeWeb.loadAppBundleAsset('test.html');
@darkredz
darkredz / gist:3116167
Created July 15, 2012 10:11
UIWebView load HTML methods
nativeWeb.loadDocumentAsset();
nativeWeb.loadString();
nativeWeb.loadURL();
@darkredz
darkredz / gist:3116175
Created July 15, 2012 10:15
UIWebView ane events
nativeWeb.addEventListener(UIWebViewEvent.FINISH_LOAD, onFinishLoad);
nativeWeb.addEventListener(UIWebViewEvent.LOCATION_CHANGE, onLocationChange);
nativeWeb.addEventListener(UIWebViewEvent.JS_TRIGGER_AS3, onJsTriggerAs);
nativeWeb.addEventListener(UIWebViewEvent.URL_SCHEME_TRIGGER, onUrlScheme);
@darkredz
darkredz / gist:3116189
Created July 15, 2012 10:23
JS AS3 communication
function triggerAS3(funcName, param){
if(param){
if(typeof param == "string")
window.location = 'as3:'+ funcName +':' + param;
else
window.location = 'as3:'+ funcName +':' + JSON.stringify(param);
}else{
window.location = 'as3:'+ funcName;
}
}
@darkredz
darkredz / gist:3116198
Created July 15, 2012 10:28
Change AS3 URI Scheme for UIWebView
//set as3 uri scheme, you can change the default behavior as3:functionName:params
nativeWeb.as3FuncUrlScheme = 'air'; //air:funcName:paramIfAny
nativeWeb.as3FuncUrlScheme = 'wooohooo'; //woohooo:funcName:paramIfAny
@darkredz
darkredz / gist:3116217
Created July 15, 2012 10:38
URI Scheme trigger in UIWebView ane
//if you want to handle mailto and skype scheme in your app
nativeWeb.urlSchemes = ["mailto", "skype"];
nativeWeb.addEventListener(UIWebViewEvent.URL_SCHEME_TRIGGER, onUrlScheme);
function onUrlScheme(event:UIWebViewEvent):void
{
//do something with it
//event.url = mailto:me@abcdef.com
trace( 'URI scheme detected: ' + event.url );
}
@darkredz
darkredz / gist:3116224
Created July 15, 2012 10:42
Capture bitmap of UIWebView
//img is a spark Image class in Flex
//capture full page content screen shot
img.source = nativeWeb.captureScreenShotAsByteArray();
//capture current visible only
img.source = nativeWeb.captureScreenShotAsByteArray(true);
//capture full page content screen shot but return bitmap data
img.source = nativeWeb.captureScreenShotAsBitmapData();
img.source = nativeWeb.captureScreenShotAsBitmapData(true);
@darkredz
darkredz / gist:3116229
Created July 15, 2012 10:44
UIWebView behavior scrolling and zooming
nativeWeb.scrollBounceEffect = false;
nativeWeb.scrollable = false;
nativeWeb.zoomable = true;
@darkredz
darkredz / gist:3116251
Created July 15, 2012 10:55
Destroying UIWebView Air native extension
//dispose this native web instead of setting it null
nativeWeb.dispose();
//dispose all instance created, convenient if you need to destroy all.
UIWebView.disposeAll();
@darkredz
darkredz / gist:3116264
Created July 15, 2012 10:59
Calling Javascript function from Adobe AIR UIWebView
//from AS3, call JS function named alertUserName
var obj:Object = {username: "superadmin"};
nativeWeb.callJsFunc('alertUserName', obj);
//in Javascript
function alertUserName(obj){
obj = JSON.parse(obj);
alert(obj.username);
}