john.c.cartwright

error registering an event handler on a FeatureLayer when using AMD

Discussion created by john.c.cartwright on Apr 8, 2013
Latest reply on Apr 9, 2013 by john.c.cartwright
Hello All,

I'm trying to register a onMouseOver event on a FeatureLayer, like the following:

var featureLayer = new FeatureLayer('http://maps.ngdc.noaa.gov/arcgis/rest/services/web_mercator/ufn/MapServer/5', {
   mode: FeatureLayer.MODE_ONDEMAND,
   outFields: ["*"]
});

map.addLayer(featureLayer);

//Error: Target must be an event emitter
on(featureLayer, "onMouseOver", function(evt) {
   console.log('inside onMouseOver');
});


and it fails with an: "Error: Target must be an event emitter".  The code above is wrapped in a ready().  Strangely a similar non-AMD sample works fine:

var featureLayer = new esri.layers.FeatureLayer('http://maps.ngdc.noaa.gov/arcgis/rest/services/web_mercator/ufn/MapServer/5', {
   mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
   outFields: ["*"]
});

map.addLayer(featureLayer);

dojo.connect(featureLayer, "onMouseOver", function(evt) {
   console.log('inside onMouseOver');
});


Any ideas on what I'm doing wrong in the first case?

Thanks!

--john

Outcomes