private var g:Graphic=new Graphic(); private function addGraphic ():void { graphicsLayer.add(g); }
RangeError: Error #2006: The supplied index is out of bounds. at flash.display::DisplayObjectContainer/addChildAt() at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()at mx.core::UIComponent/addChildAt() at com.esri.ags.layers::GraphicsLayer/collectionAddHandler() 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/addItemsToView() at mx.collections::ListCollectionView/listChangeHandler() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.collections::ArrayList/internalDispatchEvent() at mx.collections::ArrayList/addItemAt() at mx.collections::ListCollectionView/addItemAt() at mx.collections::ListCollectionView/addItem() at com.esri.ags.layers::GraphicsLayer/add() at gtest/button1_clickHandler() at gtest/___gtest_Button1_click()
http://help.arcgis.com/en/webapi/flex/samples/index.html
Here are 11 samples, the 1-st of them "Adding Graphics" - i shows how to add graphics.
<fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.geometry.Geometry; import com.esri.ags.geometry.MapPoint; import mx.utils.StringUtil; /** * Listen map mouse down handler */ protected function myMap_mapMouseDownHandler(event:MapMouseEvent):void { var grGeometry:MapPoint = event.mapPoint; var grAttributes:Object = new Object(); grAttributes.creationDate = new Date().toString(); var gr1:Graphic = new Graphic(grGeometry, sms, grAttributes); gr1.toolTip = gr1.attributes.creationDate; var gr2:Graphic = new Graphic(grGeometry, sms, grAttributes); gr2.toolTip = gr2.attributes.creationDate; var grId1:String = myGraphicsLayer.add(gr1); var grId2:String = myGraphicsLayer.add(gr2); trace(StringUtil.substitute("Graphic with id: {0} added.", grId1)); trace(StringUtil.substitute("Graphic with id: {0} added.", grId2)); } ]]> </fx:Script>
Yes, actually, you can not add a the same Graphic to a GraphicsLayer twice.
Can you tell, what is the base idea? Why do you need in 2 absolutely equals graphics in 1 layer?<fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.MapMouseEvent; import com.esri.ags.geometry.Geometry; import com.esri.ags.geometry.MapPoint; import mx.utils.StringUtil; /** * Listen map mouse down handler */ protected function myMap_mapMouseDownHandler(event:MapMouseEvent):void { var grGeometry:MapPoint = event.mapPoint; var grAttributes:Object = new Object(); grAttributes.creationDate = new Date().toString(); var gr1:Graphic = new Graphic(grGeometry, sms, grAttributes); gr1.toolTip = gr1.attributes.creationDate; var gr2:Graphic = new Graphic(grGeometry, sms, grAttributes); gr2.toolTip = gr2.attributes.creationDate; var grId1:String = myGraphicsLayer.add(gr1); var grId2:String = myGraphicsLayer.add(gr2); trace(StringUtil.substitute("Graphic with id: {0} added.", grId1)); trace(StringUtil.substitute("Graphic with id: {0} added.", grId2)); } ]]> </fx:Script>