Hi,
I have got a question to something happening in my code that I do not
understand. The following code has one for-loop. If this loop is
started by the result-event of the http-service (getImmoMarkerData-
function as shown below) I get the following error: error 1009 cannot
access a property or method of a null object reference (actually I
want to create polygons based on coordinates from a DB, but I reduced
the code in order to narrow down the problem).
On the other hand, when I put the for loop at the end of the mapready-
function everything works fine. Why is that??
Thanks in advance! Padraig

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
                                width="100%" height="100%" layout="absolute"
viewSourceURL="srcview/index.html"
creationComplete="application1_creationCompleteHandler(event)">



        <mx:Script>
                <![CDATA[
                        import com.google.maps.InfoWindowOptions;
                        import com.google.maps.LatLng;
                        import com.google.maps.LatLngBounds;
                        import com.google.maps.Map;
                        import com.google.maps.MapEvent;
                        import com.google.maps.MapMouseEvent;
                        import com.google.maps.MapType;
                        import com.google.maps.controls.ZoomControl;
                        import com.google.maps.overlays.Marker;
                        import com.google.maps.overlays.Polygon;
                        import com.google.maps.overlays.PolygonOptions;

                        import flash.events.Event;
                        import flash.geom.Point;
                        import flash.utils.Dictionary;

                        import mx.controls.Alert;
                        import mx.events.FlexEvent;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.events.ResultEvent;
                        import mx.utils.ObjectUtil;

                        private var map:Map;
                        private var polygons:Object;

                        public var searchAreas:Object = {'a' : [new LatLng(47, 
11), new
LatLng(47, 12), new LatLng(46, 12), new LatLng(46, 11), new LatLng(47,
11)]};

                        //event:ResultEvent

                        public function getImmoMarkerData():void{
                                for (var said:String in searchAreas) {
                                        var polygon2:Polygon = 
createPoly2(said);
                                        map.addOverlay(polygon2);
                                }
                        }

                        public function onHolderCreated(event:Event):void {
                                map = new Map();
                                map.key = "ABQIAAAA4r7wuAXgpbeP-
uTYTv9mgxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxS2BGFFtlZZC--wVce0f1WaOVmX3w";
                                map.addEventListener(MapEvent.MAP_READY, 
onMapReady);
                                mapHolder.addChild(map);
                        }

                        public function onHolderResized(event:Event):void {
                                map.setSize(new Point(mapHolder.width, 
mapHolder.height));
                        }

                        private function onMapReady(event:Event):void {
                                map.enableScrollWheelZoom();
                                map.enableContinuousZoom();
                                map.setCenter(new LatLng(42, -99), 3, 
MapType.NORMAL_MAP_TYPE);
                                map.addControl(new ZoomControl());
                        }

                        private function createPoly2(said:String):Polygon {
                                trace("said: " + said);
                                trace("searchAreas: " + searchAreas[said]);

                                var optionsDefault2:PolygonOptions = new
PolygonOptions( { fillStyle: { alpha: 0.2 }} );
                                var optionsHover:PolygonOptions = new 
PolygonOptions( { fillStyle:
{ alpha: 0.9 }} );
                                var polygon2:Polygon = new 
Polygon(searchAreas[said],
optionsDefault2);

                                polygon2.addEventListener(MapMouseEvent.CLICK,
function(event:MapMouseEvent): void {
                                trace("InfoWindow");
                                //map.openInfoWindow(event.latLng, new 
InfoWindowOptions({content:
stateCode}));
                                });
                                
polygon2.addEventListener(MapMouseEvent.ROLL_OVER,
function(event:MapMouseEvent): void {
                                polygon2.setOptions(optionsHover);
                                });
                                
polygon2.addEventListener(MapMouseEvent.ROLL_OUT,
function(event:MapMouseEvent): void {
                                polygon2.setOptions(optionsDefault2);
                                });

                                return polygon2;
                        }

                        //Fehler beim Datenabruf: Aktivierung notwendig
                        private function onError(event:FaultEvent):void{
                                Alert.show("Die Datenbank wird zur Zeit 
gewartet. Bitte versuchen
Sie es später " +
                                        "nochmals (14)");
                                Alert.show(event.fault.name + ":" + 
event.fault.faultString);
                        }

                        protected function
application1_creationCompleteHandler(event:FlexEvent):void
                        {
                                getData.send();
                        }

                ]]>
        </mx:Script>

        <mx:Panel title="StateMap" width="100%" height="100%">
                <mx:UIComponent id="mapHolder"
                                                
initialize="onHolderCreated(event);"
                                                resize="onHolderResized(event)"
                                                width="100%" height="100%"/>
        </mx:Panel>

        <mx:HTTPService id="getData" url="http://localhost/polygontest/php/
generate_xml_poly.php" resultFormat="e4x" useProxy="false"
method="POST" result="getImmoMarkerData()" fault="onError(event)" >
                <mx:request xmlns="">

                </mx:request>
        </mx:HTTPService>


</mx:Application>

-- 
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