The GraphicEvent.GRAPHIC_ADD method is probably your best approach. I tried it out and it works on all Selection Modes and gives you access to the graphic when it is added.
package org.lacsd.layers
{
import com.esri.ags.Graphic;
import com.esri.ags.events.GraphicEvent;
import com.esri.ags.events.GraphicsLayerEvent;
import com.esri.ags.layers.FeatureLayer;
import flash.events.MouseEvent;
import mx.utils.ObjectUtil;
public class TestFeatureLayer extends FeatureLayer
{
public function TestFeatureLayer(url:String=null, proxyURL:String=null, token:String=null)
{
super(url, proxyURL, token);
this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd);
this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove);
this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear);
}
private function addListener(graphic:Graphic):void
{
graphic.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void
{
graphic.useHandCursor = true;
graphic.buttonMode = true;
map.openHandCursorVisible = false;
trace("mouse over");
});
graphic.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void
{
graphic.useHandCursor = false;
graphic.buttonMode = false;
map.openHandCursorVisible = true;
trace("mouse out");
});
graphic.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void
{
trace("Click");
})
}
private function onGraphicAdd(event:GraphicEvent):void
{
trace("graphic has been added", ObjectUtil.toString(event.graphic.attributes));
this.addListener(event.graphic);
// add listeners here
}
private function onGraphicRemove(event:GraphicEvent):void
{
trace("graphic has been removed", ObjectUtil.toString(event.graphic.attributes));
// remove listeners here
}
private function onGraphicsClear(event:GraphicsLayerEvent):void
{
// may want to find a way to remove listeners here or add them with a weak reference
}
}
}
I think the reason you can't override the add() method for FeatureLayer is because the internal Relate/Query tasks interact directly with the GraphicsProvider/SelectedFeatures.