Gines,
This is a common problem when creating event handlers in a loop. When
the event handler runs it does not have the same scope as when it was
created. It is kind of hard to exlain but basically the handler
funcitons contain a reference to a value from when each was created
but that value was replaced in each iteration of the loop so by the
time any of the handlers run it contains the last value of the loop.
One way to solve this problem is to use "function closures". By
creating the handler in a separate function, with the data you want to
be able access when the handler runs passed as parameters, your
handler will have access to those unique values.
See this thread for an example:
http://groups.google.gm/group/google-maps-api-for-flash/browse_thread/thread/f0a873f397172119/846229402d99d05d?hl=en#846229402d99d05d

Hope that helps.


On Sep 1, 11:15 am, Gines <[email protected]> wrote:
> Hello All,
>
> I am facing an issue when creating markers in a flex app. They are
> plotted in a right way, but when I click in any one of them I get
> always the last marker data. On the example below I am trying to alert
> the tooltip for an specific marker when clicked.
>
> Thanks a lot,
>
> Gines
>
>                        private function onResult(e:ResultEvent):void
>                        {
>                                var m:Marker;
>                                var options:MarkerOptions;
>
>                                map.setCenter(new LatLng
> (-15.623036831528251, -49.5703125), 4,
> MapType.PHYSICAL_MAP_TYPE);
>                                list = e.result.map.loc;
>                                for(var i:int=0; i<list.length; i++)
>                                {
>                                                options = new
> MarkerOptions();
>                                                var stroke:StrokeStyle
> = new StrokeStyle({color: 0x300000 });
>                                                var fill:FillStyle =
> new FillStyle({color: 0xFF0000, alpha:
> 0.8});
>                                                options.label = "";
>                                                options.radius = 8;
>                                                options.tooltip = list
> [i].name;
>                                                options.hasShadow =
> true;
>                                                options.strokeStyle =
> stroke;
>                                                options.fillStyle =
> fill;
>                                                options.gravity = 0.5;
>                                                var position:LatLng =
> new LatLng(list[i].lat, list[i].lon);
>                                                m = new Marker
> (position, options);
>                                                m.addEventListener
> (MapMouseEvent.CLICK, function
> (event:MapMouseEvent):void {
>                                                map.setCenter(new LatLng
> (event.latLng.lat
> (),event.latLng.lng()), 14, MapType.NORMAL_MAP_TYPE);
>                                                        Alert.show
> (m.getOptions().tooltip);
>                                                });
>
>                                        map.addOverlay(m);
>
>                                }
>                        }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to