Question

Does anyone know how to pass data from javascript to actionscript in flex? I have tried the method involving the LocationChangeEvent listener in flex, but I have trouble getting the changed URL. I am working on a Flex Mobile project. Please help.

[Edit] I am working on a mobile project where I am trying to load a html with javascript in it. I set the size of the StageWebView to zero because I dont need the web interface, I just need to load the javascript. From there, I am trying to send data to my flex application by modifying the document.location inside the javascript like this:

document.location = "mydata";

Then, my flex application is listening to this event LocationChangeEvent where it will be triggered if there has been a change of URL happened inside the StageWebView. For some reason, I does not trigger.

[Solved] The LocationChangeEvent is actually working in my case but I did change something in the javascript.

I changed the following

document.location = "mydata";

to

window.location = "mydata";
Was it helpful?

Solution 2

You could try listening for LocationChangeEvent.LOCATION_CHANGING or Event.COMPLETE on your StageWebView (note that there is LOCATION_CHANGE and LOCATION_CHANGING)

var myStageWebView:StageWebView = new StageWebView();
myStageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, handler);
myStageWebView.addEventListener(Event.COMPLETE, onComplete);

or

In your change/changing/complete handler, trace event.target to see the html. Maybe you could simply add your javascript redirect url to the html body when it loads.

Using StageWebViews for data on mobile can be a little convoluted. Alternatively, if you have access to server code, you could try making a POST using a URLLoader to get the proper redirect url from the server (thus bypassing the need for javascript). In your complete handler for the URLLoader, access the returned data from event.currentTarget.data and pass that into your StageWebView location.

OTHER TIPS

You can make calls like Actionscript -> Javascript and Javascript -> Actionscript with

ExternalInterface

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top