Logic flow confusion

[LEFT]If a public method of an instance sets up the event listeners, then how can the results of those listener methods be returned?[/LEFT]

Hi all,

I am a bit confused with a situation i have. I will try to explain as best i can.

Ok this is for google maps but bare with me coz its not really focused on that.

With google maps, in order to search the map from a string then you need to use the google map API to send that string to google and have googles API return a Latitude/Longitude co-ordinate.

I do not know how to write a method for my maps class that returns a value. Here is an unrelated basic local class.

 
private var someVar:String = "hi";
 
public function doReturnString(): String
{
    return someVar;
}

That means some other class can call Map.doReturnString();

var myword:String = Map.doReturnString() as String;    //hi

[LEFT]But what about if you need to wait for information? Back to maps…[/LEFT]


[LEFT]public function doReturnGeocode(s:String): void
{
  var geo:ClientGeocoder = new ClientGeocoder();
  geo.addEventListener(GeocoderEvent.FAILURE, onFailure);
  geo.addEventListener(GeocoderEvent.SUCCESS, onSuccess);
  geo.geocode(s);
}[/LEFT]

[LEFT]There is nothing to return… So pretend i wanted to ask for the geocode of a user inputted place and put a marker on the map at that place… The above method will return nothing. The only way i can think to do it is inside the onSuccess method[/LEFT]


[LEFT]private function onSuccess(e:GeocoderEvent): void
{
 var myCoords:LatLng = e.result.lastResult as LatLng;    //here is my geocode info!
}[/LEFT]

[LEFT]However there seems to be no way i can access that information from the outside and it means creating a new SUCCESS and FAILURE method for each feature (panning, zooming, goto, centre screed, bounds…).[/LEFT]

[LEFT]Id just like to call a public method… have it do all the work with google and then return the information back to the user like below.[/LEFT]

[LEFT]var user:LatLng = map.doReturnGeocode(“Edinburgh, Scotland, UK”);[/LEFT]

[LEFT]Is this making any sense to anyone?[/LEFT]

[LEFT]Thanks![/LEFT]