crooksy88
crooksy88

Reputation: 3851

StageWebViewBridge loading and communicating with online page

Has anyone been successful in using StageWebViewBridge to load and communicate with an online web page?

http://code.google.com/p/stagewebviewbridge/wiki/Communication

The documentation and examples offered are all configured around working with local files (which work successfully) and although the instruction to 'include the StageWebViewBridge.js' file within the loaded html page sounds very straight forward, sadly it doesn't seem to work.

For anyone wanting to replicate my test I have uploaded the files here:

http://www.infin8design.com/clients/stack/swvb.zip

I'm basically loading the 'ExampleCallBackFuncions.html' file from a web server. I've included the StageWebViewBridge.js file like so...

<script type="text/javascript" src="StageWebViewBridge.js"></script>

When I test the movie I get the correct setup output messages

_serializeObject =>___onDomReady
_serializeObject =>___getFilePaths
_serializeObject =>___onDeviceReady
_serializeObject =>fnCalledFromJS

and the html page appears in the viewport. But on pressing the button which should send a message to Actionscript I get the following error messages:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at es.xperiments.media::StageWebViewBridgeExternal/parseCallBack()[/Users/G5TowerIntel/Desktop/maptest/es/xperiments/media/StageWebViewBridgeExternal.as:88] at es.xperiments.media::StageWebViewBridge/onLocationChange()[/Users/G5TowerIntel/Desktop/maptest/es/xperiments/media/StageWebViewBridge.as:236]

My goal is to send a message back to ActionScript from the html page.

Thanks,

Mark

Upvotes: 1

Views: 3199

Answers (2)

crooksy88
crooksy88

Reputation: 3851

Success! Here's the AS3 I've used...

public var webView1:StageWebViewBridge;

public function Main() {            
StageWebViewDisk.addEventListener(StageWebviewDiskEvent.END_DISK_PARSING, onInit );
StageWebViewDisk.setDebugMode( true );
StageWebViewDisk.initialize(stage);
}

function onInit( e:StageWebviewDiskEvent ):void {
trace("onInit");
webView1 = new StageWebViewBridge(60, 60, 400, 262);
webView1.addEventListener(StageWebViewBridgeEvent.DEVICE_READY, onDeviceReady );
webView1.loadURL("http://www.domain.com/ExampleCallBackFuncions.html");
}

function onDeviceReady( e:StageWebViewBridgeEvent ):void {
trace("onDeviceReady"); 
webView1.addCallback('fnCalledFromJS', fnCalledFromJS );
addChild(webView1);

}

And the example ExampleCallBackFuncions.html file was modified to include the StageWebViewBridge.js file like so...

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>example</title>
<script type="text/javascript" src="StageWebViewBridge.js"></script>
...

Upvotes: 0

xperiments
xperiments

Reputation: 106

You are doing some things wrong in your code....

You must listen to DEVICER_READY event before do any comm between as3 and js and viceversa...

// listen StageWebViewBridgeEvent.DEVICE_READY event to be sure 
// the communication is ok
view.addEventListener(StageWebViewBridgeEvent.DEVICE_READY, onDeviceReady );

// add a callback method for the function we like to call from Javascript
view.addCallback('fnCalledFromJS', fnCalledFromJS );

// load the localfile demo.html ( inside the www dir )
view.loadLocalURL('http://www.someserver.com/ExampleBasic.html');

You can take my ExampleBasic and change the line with:

view.loadLocalURL('applink:/ExampleBasic.html');

to

view.loadURL('http://localhost/ExampleBasic.html');

Then in the server html file add the line with reference to the .js file

It must work...

Say me...

Upvotes: 2

Related Questions