This can also usually be accomplished using function closures.
If you use a separate function to create a marker that takes as
parameter(s) the unique data about the marker, and use an anonymous
function for the click event handler defined within the create
function, you will still have access to the parameters that you passed
in.
For example:
private function createMarker(latlng:LatLng, uniqueID:String):Marker {
var marker:Marker = new Marker(latlng, new MarkerOptions({....}));
marker.addEventListener(MapMouseEvent.CLICK, function
(e:MapMouseEvent):void {
trace ("You clicked marker " + uniqueID);
});
return marker;
}
As far as I know you can't explicitly remove an event listener that
uses an anonymous function however, so if you need to remove them at
some point, ie marker is no longer clickable, you probably shouldn't
use this technique. Another thing to remember is that within the
anonymous function the "this" object does not refer to the current
instance of the class that the method belongs to, although the
properties and methods of the instance are still available.
Hope this helps.
On Aug 26, 12:38 am, Andrew <[email protected]> wrote:
> We had this same need. we store listings in a manager and place them
> individually on the map. our solution required setting a "marker"
> value on each object in the dataset to equal the marker's "foreground"
> object when the marker is created. we use the foreground object
> (which is a display object) because it turns out the marker object
> itself cant be referenced later (don't know why). here's the idea:
>
> (when the listing's marker is placed on the map)
> listingInManager.marker = newMarkerOnMap.foreground;
>
> (where you need to get a listing ID back ground the marker)
> var listingId = ListingManager.getListingFromMarker
> ( theMarker ).listingId;
>
> (how the manager does that)
> for each ( var listing in mListingContainer )
> {
> if ( listing.marker === pMarker )
> {
> return listing;
> }
> }
>
> On Aug 25, 11:59 am, larry22 <[email protected]> wrote:
>
> > Is there a way to return a Flash instance name when a marker is
> > clicked?
>
> > I am trying to associate other data with a marker.. so that when a
> > marker is clicked... the app essentially says "you clicked marker 1"
> > and gets all other data from another data source about marker 1.....
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---