0

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";
1
  • 1
    You should explain a bit more about your setup. Where is the javascript you want to pass data from? Is is in the browser? Commented Jul 4, 2013 at 13:20

2 Answers 2

4

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

ExternalInterface

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I forgot to mention that I am working on Flex Mobile project
0

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.

1 Comment

Thank you for your answer. It turns out that this is a working solution but there is one catch to the JS. I changed the document.location to window.location and I am able to detect the url changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.