Jonathan,

That's exactly what I did.  I have the references correct in embed
statement because in Flex it throws an error when the path is
incorrect.  Now the only thing that I see that is different in the
code you sent me is that the customIcon was removed from the new
MarkerOptions.

Perhaps you will be able to see something in my code, which I'll paste
below.   I've combined the Store Finder demo and the xml parsing
demo.. works perfectly except for the customIcons.   I'm pulling the
data from a mysql database I have set up locally.




Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright 2008 Google Inc.
 Licensed under the Apache License, Version 2.0:
    http://www.apache.org/licenses/LICENSE-2.0
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
xmlns:maps="com.google.maps.*" layout="absolute" width="100%"
height="100%" viewSourceURL="srcview/index.html"
xmlns:comp="components.*">
  <mx:Panel title="Google Maps API for Flash Demo" width="100%"
height="100%">
  <mx:HDividedBox width="100%" height="100%">
 <mx:VBox width="100%" height="100%">
  <mx:HBox>
      <mx:Label
     text="Address: " width="70"/>
     <mx:TextInput id="address" text="Seattle WA" width="100%" />
  </mx:HBox>
  <mx:HBox>
      <mx:Label
     text="Radius: "
     width="70"/>
   <mx:ComboBox
       id="radius">
     <mx:dataProvider>
      <mx:Array>
       <mx:String>25</mx:String>
       <mx:String>100</mx:String>
       <mx:String>200</mx:String>
      </mx:Array>
     </mx:dataProvider>
   </mx:ComboBox>
  </mx:HBox>
  <mx:Button
     id="submitButton" label="Search Locations"
     click="searchLocations(event);"
  />
  <mx:HRule
      width="100%"
    strokeColor="0xC4CCCC"
    shadowColor="0xEEEEEE"
    strokeWidth="2"
  />
  <mx:DataGrid id="storeLocationsGrid" dataProvider="{storeLocations}"
width="100%" height="100%" sortableColumns="true" itemClick="showStore
(event)">
     <mx:columns>
            <mx:Array>
                <mx:DataGridColumn dataField="StoreInfo">
                  <mx:itemRenderer>
                    <mx:Component>
                    <mx:Text width="100%" selectable="false"
htmlText="{data.StoreInfo}"/>
                    </mx:Component>
                  </mx:itemRenderer>
               </mx:DataGridColumn>
                <mx:DataGridColumn dataField="Distance" width="70"/>
            </mx:Array>
        </mx:columns>
  </mx:DataGrid>
  </mx:VBox>
   <maps:Map
    id="map"
    key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-
iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g"
    mapevent_mapready="onMapReady(event)"
    width="100%" height="100%"/>
  </mx:HDividedBox>
 </mx:Panel>
 <mx:Script>
    <![CDATA[
      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.overlays.Marker;
      import com.google.maps.overlays.MarkerOptions;
      import com.google.maps.InfoWindowOptions;
      import com.google.maps.services.ClientGeocoder;
      import com.google.maps.services.GeocodingEvent;
      import mx.controls.Alert;
      import mx.collections.ArrayCollection;
      import com.google.maps.controls.ZoomControl;

      [Bindable] private var storeLocations:ArrayCollection = new
ArrayCollection();

      private function onMapReady(event:Event):void {
        map.enableScrollWheelZoom();
        map.enableContinuousZoom();
        map.setCenter(new LatLng(40, -100), 4);
        map.addControl(new ZoomControl());
      }

      [Embed(source="../assets/images/blue-dot.png")] private var
blueIcon:Class;

      [Embed(source="../assets/images/green-dot.png")] private var
greenIcon:Class;



      [Bindable]
      private var customIcons:Object =
        {"restaurant": blueIcon, "bar": greenIcon};

      private function searchLocations(event:Event):void {
        var geocoder:ClientGeocoder = new ClientGeocoder();
        geocoder.addEventListener(
          GeocodingEvent.GEOCODING_SUCCESS,
          function(event:GeocodingEvent):void {
          var placemarks:Array = event.response.placemarks;
          if (placemarks.length > 0) {
            searchLocationsNear(placemarks[0].point);
          }
        });
        geocoder.addEventListener(
          GeocodingEvent.GEOCODING_FAILURE,
          function(event:GeocodingEvent):void {
            Alert.show("Geocoding failed");
          });
        geocoder.geocode(address.text);
      }

    public function searchLocationsNear(center:LatLng):void {
     // var searchUrl:String = 'http://imagine-it.org/storelocator/
phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng()
+ '&radius=' + radius.text;
     var searchUrl:String = 'http://localhost/mapProject/connections/
genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius='
+ radius.text;
     var xmlString:URLRequest = new URLRequest(searchUrl);
     var xmlLoader:URLLoader = new URLLoader(xmlString);
     xmlLoader.addEventListener("complete", parseLocationsXml);
    }

    public function parseLocationsXml(event:Event):void{
        map.clearOverlays();
        storeLocations.removeAll();

        var markersXML:XML = new XML(event.target.data);
        var markers:XMLList = markersXML..marker;
        var markersCount:int = markers.length();
        if (markersCount == 0) {
         map.setCenter(new LatLng(40, -100), 4);
         Alert.show("No stores found. Try a different address");
         return;
       }
       var bounds:LatLngBounds = new LatLngBounds();
        for (var i:Number = 0; i < markersCount; i++) {
            var markerXml:XML = markers[i];
            var name:String = markerx...@name;
            var address:String = markerx...@address;
            var distance:Number = new Number(markerx...@distance);
            var type:String = markerx...@type;
            var latlng:LatLng = new LatLng(markerx...@lat,
markerx...@lng);
            var storeInfo:String = "<b>" + name + "</b>\n<br/>" +
address;
            var marker:Marker = createMarker(latlng, name, storeInfo,
type);
            storeLocations.addItem({StoreInfo: storeInfo, Distance:
distance.toFixed(2), Marker: marker});
            bounds.extend(latlng);
            // customIcons[type].markers.push(marker);
            map.addOverlay(marker);
        }
        storeLocations.refresh();
        map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel
(bounds));
    }


     public function createMarker(latlng:LatLng, name:String,
storeInfo:String, type:String): Marker {
                        var marker:Marker = new Marker(latlng, new MarkerOptions
({iconOffset: new Point(-16, -32)}));
                       // var marker:Marker = new Marker(latlng, new 
MarkerOptions
({icon: new customIcons[type], iconOffset: new Point(-16, -32)}));
                       //var storeInfo:String = "<b>" + name + "</b> <br/>" +
address;
                        marker.addEventListener(MapMouseEvent.CLICK, function
(e:MapMouseEvent):void {
                          marker.openInfoWindow(new InfoWindowOptions
({contentHTML:storeInfo}));
                        });
                        return marker;
                     }



     public function showStore(event:Event):void {
         var marker:Marker = storeLocationsGrid.selectedItem.Marker;
           marker.dispatchEvent(new MapMouseEvent(MapMouseEvent.CLICK,
marker, marker.getLatLng(), true, false));
     }

    ]]>
  </mx:Script>
</mx:Application>





On Jan 11, 6:25 pm, Jonathan Wagner <[email protected]> wrote:
> Hey David,
>
> you could just make sure the embed sources to the custom icons are
> correct, if you're working in a flex project, the local directory is
> the src folder. So if you put the images under src it would be:
>
>   [Embed(source="./blue-dot.png")] private var
> blueIcon:Class;
>   [Embed(source="./green-dot.png")] private var
> greenIcon:Class;
>
> Jonathan
> Scribblemaps.com
>
> On Jan 11, 6:51 pm, Jonathan Wagner <[email protected]> wrote:
>
> > Hey David,
>
> > I loaded the demo, the problem is coming from the custom icons:
>
> >   [Embed(source="../../images/blue-dot.png")] private var
> > blueIcon:Class;
> >   [Embed(source="../../images/green-dot.png")] private var
> > greenIcon:Class;
>
> > Since neither of these two images exist, when the code tries to
> > instantiate the class, it fails. A constructor is a primary function
> > of a class. To fix the bug use this:
>
> > public function createMarker(latlng:LatLng, name:String,
> > address:String, type:String): Marker {
> >         var marker:Marker = new Marker(latlng, new MarkerOptions
> > ({iconOffset: new Point(-16, -32)}));
> >         var html:String = "<b>" + name + "</b> <br/>" + address;
> >         marker.addEventListener(MapMouseEvent.CLICK, function
> > (e:MapMouseEvent):void {
> >           marker.openInfoWindow(new InfoWindowOptions
> > ({contentHTML:html}));
> >         });
> >         return marker;
> >      }
>
> > Jonathan
> > Scribblemaps.com
>
> > On Jan 11, 11:49 am, David Green <[email protected]> wrote:
>
> > > Group,
>
> > > I was hoping that I'd be able to figure out the answer to why I'm
> > > getting errors using the xml parsing demo for google maps for
> > > flash.    Jonathan wrote back and referred me to Pamela's KML Demo but
> > > I'm not using KML at all..
>
> > > I'm wondering if anyone has a fix for the error in the xml parsing
> > > demo or is there another approach I should be using?  I can't seem to
> > > find the answer anywhere on the net.
>
> > > I'm using Flex 3 and mysql/php to parse the xml
>
> > > The exact error on the demos are:
>
> > > TypeError: Error #1007: Instantiation attempted on a non-constructor.
> > >         at XmlParsingDemo/createMarker()
> > >         at XmlParsingDemo/readXml()
> > >         at flash.events::EventDispatcher/dispatchEventFunction()
> > >         at flash.events::EventDispatcher/dispatchEvent()
> > >         at flash.net::URLLoader/onComplete()
>
> > > Are the demo's on the Google maps site depreciated?  They also throw
> > > an error when viewed in the browser.
>
> > > I get the error on the tutorial located 
> > > herehttp://code.google.com/apis/maps/articles/phpsqlflex.html and an
> > > error on the demo located 
> > > athttp://gmaps-samples-flash.googlecode.com/svn/trunk/demos/XmlParsingD...
>
> > > Thanks for your help..
>
> > > David G.
>
> > > On Jan 7, 10:02 pm, Jonathan Wagner <[email protected]> wrote:
>
> > > > Pamela posted some other stuff for processing KML, try out this:
>
> > > > Here's the 
> > > > reference:http://gmaps-utility-library-flash.googlecode.com/svn/trunk/docs/com/...
>
> > > > Here's the 
> > > > demo:http://gmaps-utility-library-flash.googlecode.com/svn/trunk/examples/...
>
> > > > Jonathan
> > > > Scribblemaps.com
>
> > > > On Jan 7, 10:00 pm, David Green <[email protected]> wrote:
>
> > > > > I am learning to work with Google Maps using Flex.   I recreated the
> > > > > xml parsing demo locally and it kept throwing the error TypeError:
> > > > > Error #1007Instantiationattemptedon anon-constructorerror.   At
> > > > > first I thought it was something that I was doing wrong so I went back
> > > > > to look at the demo again.
>
> > > > > I discovered the demo on the site is throwing the same error in the
> > > > > both IE and Firefox browsers..  (I'll paste it below).
>
> > > > > I have the debug version of flash installed and apparently it is
> > > > > catching the error.   Does anyone know what to do to fix the problem?
>
> > > > > URL:http://gmaps-samples-flash.googlecode.com/svn/trunk/demos/XmlParsingD...
>
> > > > > TypeError: Error #1007:Instantiationattemptedon anon-constructor.
> > > > >     at XmlParsingDemo/createMarker()
> > > > >     at XmlParsingDemo/readXml()
> > > > >     at flash.events::EventDispatcher/dispatchEventFunction()
> > > > >     at flash.events::EventDispatcher/dispatchEvent()
> > > > >     at flash.net::URLLoader/onComplete()
>
> > > > > I think it has something to do with this function
>
> > > > > public function createMarker(latlng:LatLng, name:String,
> > > > > address:String, type:String): Marker {
> > > > >           var marker:Marker = new Marker(latlng, new MarkerOptions
> > > > > ({icon: new customIcons[type], iconOffset: new Point(-16, -32)}));
> > > > >         var html:String = "<b>" + name + "</b> <br/>" + address;
> > > > >         marker.addEventListener(MapMouseEvent.CLICK, function
> > > > > (e:MapMouseEvent):void {
> > > > >           marker.openInfoWindow(new InfoWindowOptions
> > > > > ({contentHTML:html}));
> > > > >         });
> > > > >         return marker;
> > > > >      }
>
> > > > > I really want to keep learning but this is stopping me from
> > > > > advancing.  Any help would be appreciated.
>
> > > > > 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.


Reply via email to