tuarua / WebViewANE

WebView Adobe Air Native Extension for macOS 10.10+, Windows Desktop, iOS 9.0+ and Android 19+. This ANE provides access to a more modern webview from AIR.
Apache License 2.0
183 stars 53 forks source link

Are Sync communications with javascript possible ? #152

Closed lgignoud closed 6 years ago

lgignoud commented 6 years ago

Hi Tuarua, My understanding is that all communications with javascript is asynchrone, with a callback mechanism. In an AS3 algorithm, I have to call some Google Maps function (fromLatLngToPoint for example); previously I used the synchrone function ExternalInterface.call() in the browser. I port this code to Air, and it's not easy to make all the algorithm with callbacks. Do you think there is a way to call a javascript function and get the result synchronously through the WebView ? Best, Laurent

tuarua commented 6 years ago

It is not possible to call js on the webview without a callback function. This is because the native code in Swift in OSX+iOS and C# for Windows both use async closures.

The most concise way is to use an inline closure ie

webView.evaluateJavascript("document.getElementById('output').innerHTML;", 
function onJsEvaluated(jsResult:JavascriptResult):void {
//output
})
lgignoud commented 6 years ago

OK, thanks