5 Replies Latest reply on Aug 25, 2010 2:37 PM by rtalton

    toogle  Overlays




      I'm new in AS and Flex.

      I added google map to my flex project and  added a groundoverlay.

      Now I want to have a checkbox toggle the groundoverlay (add/ remove).


      Any Ideas?





        • 1. Re: toogle  Overlays
          rtalton Level 4

          Bind the groundoverlay's visible property to the checkbox selected property to toggle visibilty.

          If you actually want to remove the overlay, you'll need to write a function which uses removeChild().

          • 2. Re: toggle  Overlays
            lis789 Level 1

            I am trying to write the function to remove the overlay, but it’s not working.

            I get the error undefined characteristic. What ist wrong?

            Do you have a tip?


            The code is:

            private function onMapReady(event:MapEvent):void {

            var KartenLoader:Loader = new Loader();

            var urlRequest:URLRequest = new URLRequest("….");


            KartenLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void {



            var groundOverlay:GroundOverlay = new GroundOverlay(


            KartenLoader, new LatLngBounds(new LatLng(….), new LatLng(….)));


            if (checkbox.selected=true)

            groundOverlay.visible = true












            checkbox.addEventListener(MouseEvent.ClICK, remove);

            function remove (event:MouseEvent):void{

            if (checkbox.selected == false);









            • 3. Re: toggle  Overlays
              rtalton Level 4

              Instead of mouse click, use the Change event to listen to the checkbox.

              • 4. Re: toggle  Overlays
                lis789 Level 1

                Thanks for your answer.


                I used Event.Change.


                checkbox.addEventListener(Event.Change, remove);

                private function remove (e:Event):void{
                                 if (checkbox.selected == false);

                I still get the error undefined characteristic groundOverlay, remove and checkbox.

                The characteristics are defined in the function above.

                I put the “checkbox.addEventListener(Event.Change, remove); “ to the "private function onMapReady (event:MapEvent) …"

                Now I get only the error undefined characteristic groundOverlay.

                But I defined the groundoverlay above.

                After some try out’s it still not working.What I have forgotten?


                • 5. Re: toggle  Overlays
                  rtalton Level 4

                  More than likely the overlay has not been created yet when the Change event is being triggered, resulting in the error.

                  Make sure the overlay has already been created before adding the listener.

                  The other thing you can do is check for its existence in your "remove" function:

                                 if (checkbox.selected == false && groundOverlay);//false if groundOverlay is undefined


                  Even simpler would be to directly bind the overlay's VISIBLE property to the checkbox' SELECTED property.


                  <goog:groundOverlay id="groundOverlay"




                  Now you will no longer get the undefined error, as Flex takes care of all that behind the scenes.