Select to view content in your preferred language

FeatureLayer.clearSelection() fails

2117
4
12-20-2011 09:13 AM
TylerWaring
Frequent Contributor
Greetings Everyone,
            I keep getting a strange error when trying to clear a selection on a feature layer. My application lets the user select a feature and then gathers information from a related stand alone table and displays the results. The code works perfectly the first time. However, the second time around the code fails on FeatureLayer.clearSelection();. The error I get is detailed below. I have no idea how to resolve this. Any suggestions will be greatly appreciated.

Best Regards, Tyler Waring

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$removeChild()
at mx.core::UIComponent/removeChild()
at com.esri.ags.layers::GraphicsLayer/collectionRemoveHandler()
at com.esri.ags.layers::GraphicsLayer/collectionChangeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ListCollectionView/dispatchEvent()
at mx.collections::ListCollectionView/removeItemsFromView()
at mx.collections::ListCollectionView/listChangeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ArrayList/internalDispatchEvent()
at mx.collections::ArrayList/removeItemAt()
at mx.collections::ListCollectionView/removeItemAt()
at com.esri.ags.layers::GraphicsLayer/remove()
at com.esri.ags.layers::FeatureLayer/removeFeatureIIf()
at com.esri.ags.layers::FeatureLayer/clearSelectionInternal()
at com.esri.ags.layers::FeatureLayer/clearSelection()
at gov.durhamnc.durhammaps.subapps.FireFlow.presentation::FireFlowPM/findHydrant()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.esri.viewer::ViewerContainer$/dispatchEvent()
at gov.durhamnc.durhammaps.subapps.FireFlow.presentation::FireFlowPM/identifyEnd()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.esri.ags.tools::DrawTool/map_clickFirstHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at com.esri.ags::Map/dispatchMapMouseEvent()
at com.esri.ags::Map/mouseUpHandler()
Tags (2)
0 Kudos
4 Replies
TylerWaring
Frequent Contributor
OK... now this is strange. So I figured out the problem. For cartographic purposes, I have a graphicsLayer that I am adding the selected feature to. Strangely enough, adding a graphic to this layer is causing my error. If I take out the line that adds the graphic to the graphicsLayer, everything works as I would expect. However, I need to be able to display which feature is selected in the featureLayer and the design requirements of my map services do not allow me to impliment featureLayer.selectionColor effectively.

Is there a way around all this that I am overlooking.

Thanks, Tyler Waring
0 Kudos
TylerWaring
Frequent Contributor
So after trying a number of different things I finally ended up with a simple solution.

instead of:

for each (var g:Graphic in event.features)
{
hydrantGraphicsLayer.add(g);
objIds.push(g.attributes.OBJECTID_1)
}

I used:

hydrantGraphic = new Graphic();
for each (var g:Graphic in event.features)
{
hydrantGraphic.geometry = g.geometry;
hydrantGraphicsLayer.add(hydrantGraphic);
objIds.push(g.attributes.OBJECTID_1)
}

I'm not sure what the difference is or why this was causing problems for me.

If anyone knows why I'd be interested in knowing.

Thanks, Tyler
0 Kudos
DasaPaddock
Esri Regular Contributor
A Graphic can only exist in one layer at a time and Graphics that are in a FeatureLayer should not be added to other layers. By creating a new Graphic you're avoiding this issue.
0 Kudos
TylerWaring
Frequent Contributor
Thanks for the info.

Tyler
0 Kudos