How do I communicate between JS and AS3 in an AIR Android Application?

笑着哭i 提交于 2019-12-05 17:53:56

You can't read the return value from javascript:getLatLong(), to get data from JS to AS3 the old trick is to set the window.location from JS, then in AS3 listen for the LOCATION_CHANGING event and parse the data out of the changing location, and event.preventDefault() so the location doesn't actually change.

AS3:

webView.loadURL("javascript:sendLatLng()");

JS:

function sendLatLng() {
    location.href = "?lat=" + lat  +"&lng=" + lng;
}

AS3:

webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChanging);

function locationChanging(e:LocationChangeEvent):void {
    e.preventDefault();
    var query:String = e.location.split("?")[1];
    var vars:URLVariables = new URLVariables(query);
    trace(vars.lat, var.lng);
}

You can try the StageWebViewBridge library to help you with this.

You could also try using a Web View ANE that supports JS communication.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!