StageWebViewBridge intermittent initializing

566 Views Asked by At

I have successfully set up StageWebViewBridge to communicate between my AIR app and web hosted JavaScript. However sometimes when I launch the app the following error is thrown:

_serializeObject =>___onDomReady
_serializeObject =>fnCalledFromJS
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at es.xperiments.media::StageWebViewBridgeExternal/parseCallBack()[Flash/es/xperiments/media/StageWebViewBridgeExternal.as:88]
    at es.xperiments.media::StageWebViewBridge/onLocationChange()[Flash/es/xperiments/media/StageWebViewBridge.as:236]

If the app launches successfully this is the trace output.

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

So it appears that registering the fnCalledFromJS callback is sometimes being called too early.

Here is the sequence of events in my code:

StageWebViewDisk.addEventListener(StageWebviewDiskEvent.END_DISK_PARSING, onInit );
StageWebViewDisk.setDebugMode( false );
StageWebViewDisk.initialize(stage);


function onInit( e:StageWebviewDiskEvent ):void{    
    webView1 = new StageWebViewBridge(19, 43, 400, 262);
    webView1.addEventListener(StageWebViewBridgeEvent.DEVICE_READY, onDeviceReady );    
    webView1.loadURL("http:www.domain.com/ipadMap.php);     
}

function onDeviceReady( e:StageWebViewBridgeEvent ):void {
    webView1.addCallback('fnCalledFromJS', fnCalledFromJS );
    // all is loaded and ok, show the view
    addChild(webView1);

}

Would anyone know how to prevent the error from being thrown?

Thanks,

Mark

1

There are 1 best solutions below

0
On

Ah. This was my mistake. I was calling the JS > AS function as the web page was being loaded.

Disabling the call has fixed the issue.