Skip to main content
Known Participant
November 17, 2011
Answered

calling an actionscript function from a webview

  • November 17, 2011
  • 1 reply
  • 1107 views

In the mobile app that I am developing I need to be able to open a webview that displays a website that is saved locally to the app. I then need to be able to press a button within that webview and have it call a function in the app itself. Is there a way to do this? Can a webview (using javascript or something) call a function in the app? If so, How?

This topic has been closed for replies.
Correct answer Innovatology

In JavaScript, set the document.location property to  some custom URL string. You could use your own URL scheme to pass parameters from JS to  AS3, e.g. as3://actions/document/save?overwrite=false. Then in ActionScript, handle the LocationChangeEvent.LOCATION_CHANGING event, and examine and/or decode the URL.

Call event.preventDefault() in your AS3 event handler to cancel the navigation and stay on the same page.

1 reply

Innovatology
InnovatologyCorrect answer
Participating Frequently
November 18, 2011

In JavaScript, set the document.location property to  some custom URL string. You could use your own URL scheme to pass parameters from JS to  AS3, e.g. as3://actions/document/save?overwrite=false. Then in ActionScript, handle the LocationChangeEvent.LOCATION_CHANGING event, and examine and/or decode the URL.

Call event.preventDefault() in your AS3 event handler to cancel the navigation and stay on the same page.

Known Participant
November 18, 2011

This is brilliant. What a clever hack. Thank you.