Skip to main content
Known Participant
Nov 17, 2011 7:18 PM UTC
Answered

calling an actionscript function from a webview

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 is closed to new replies. Start a new post to keep the conversation going.
Innovatology
InnovatologyCorrect answer
Participating Frequently
Nov 18, 2011 3:28 AM UTC

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.

2 replies

Innovatology
InnovatologyCorrect answer
Participating Frequently
Nov 18, 2011 3:28 AM UTC

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.

Translate
Known Participant
Nov 18, 2011 5:10 PM UTC

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

Translate