I have come to the final part of my app development that I have feared the
most.  I will have a lot of questions about this because I am so in the
dark, so here it goes.

I need a Google Map in my Royale project.  In Flex, this was done with an
ANE or in the older days with StageWebView.  You create an HTML document
that contains the structure for the map as well as the Javascript functions
that can add or delete markers, add or delete info windows, center the map,
etc.  The HTML file is then set as the url for the stagewebview, and you
have yourself a map.  A simple HTML version looks like this:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    
  </head>
  <body>
    <div id="map"></div>
    
    
  </body>
</html>

The challenge was communicating between the javascript in the StageWebView,
and the actionscript in Flex.  To talk with the javascript, you would simply
invoke the javascript protocol in your url, and it would call the function
after the word "javascript:" like this:

webView.loadUrl("javascript:addMarker('39.0679459','-86.148456','$350,000')");

Talking to Actionscript from Javascript was a little tricker.  StageWebView
throws an event called "locationChanging", so you could basically change the
location in javascript and throw in a string containing your information to
parse out and call your function in actionscript.  So in javascript, you
would have:

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

and you would catch it in actionscript like this:

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);
}


So I have run into a wall using the two components available in Royale to
make a similar setup, WebBrowser and IFrame.  Both are great, but only seem
to allow one way communication.  WebBrowser has a "locactionChange" event,
so I can use it to talk to actionscript the way that I was doing with
StageWebView, but adding "javascript" to the front of the url property does
not allow actionscript to call javascript functions.

IFrame on the otherhand does allow you to add "javascript" to the front of
the src property, so you can call javascript functions from actionscript,
but it does not have a "locationChange" event, so I can't send strings from
javascript to actionscript.

So I'm stuck.  One component allows me to talk from actionscript to
javascript, and the other from javascript to actionscript.  But neither does
both.  I'm kinda amateurish at creating my own classes, but I've tried to
wrap my head around trying to use @Externs, but the HTML file has to exist
inside of a webview or iframe component, so I feel trapped within the walls
of those constructs to get information into or out of those components.

Am I missing something obvious?  Is there any way that "locationChange"
could easily be added to the IFrame component, or adding the "javascript:"
protocol to the url property of the WebBrowser?




--
Sent from: http://apache-royale-users.20374.n8.nabble.com/

Reply via email to