Select to view content in your preferred language

Cancel edit event problem

2998
4
Jump to solution
09-05-2012 03:20 AM
by Anonymous User
Not applicable
Original User: arslansai

hello.
how correct cancel edit event without undo?

sample

private function editLayerStart(event:FeatureLayerEvent):void {       event.preventDefault(); }


don't work
i use editor component

[ATTACH=CONFIG]17487[/ATTACH]

[ATTACH=CONFIG]17488[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: arslansai

i did it.
(EditorSkin)(myEditor.getChildAt(0)).currentState = "normal"

it is reset editor status to normal.

View solution in original post

0 Kudos
4 Replies
IvanBespalov
Frequent Contributor
By default this event is not cancelable.
FeatureLayerEvent

FeatureLayerEvent () Constructor 
public function FeatureLayerEvent(type:String, featureLayer:FeatureLayer = null, cancelable:Boolean = false) 
Creates a new FeatureLayerEvent. 

Parameters 
type:String â?? The event type; indicates the action that triggered the event. 
  
featureLayer:FeatureLayer (default = null) â?? Reference to the associated layer. 
  
cancelable:Boolean (  default = false) â??   Specifies whether the behavior associated with the event can be prevented.


smthing like this:
protected function onSmthingChange(event:SmthingChangeEvent):void
{
  dispatchEvent(new FeatureLayerEvent(FeatureLayerEvent.EDITS_STARTING, myFeatureLayer, true);
}

protected function editLayerStart(event:FeatureLayerEvent):void
{
  if (event.cancelable)
  {
      event.preventDefault();
  }
  else
  {
      // undo only
  }
}
0 Kudos
by Anonymous User
Not applicable
Original User: arslansai

Thank you, that's understandable. I can now cancel the event. Another problem - you can tell how to reset the status of the component editor. I'm canceling the event (add an object for example), but the editor does not respond to it. Sign hanging adding an object.
[ATTACH=CONFIG]17509[/ATTACH][ATTACH=CONFIG]17510[/ATTACH]
0 Kudos
IvanBespalov
Frequent Contributor
I have not found a legal way to stop/cancel the action started by Editor component.
The only solution that I see - creating your own Editor componet
or remove/add editor each time you prevent start editing :cool:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:esri="http://www.esri.com/2008/ags"
      initialize="application_initializeHandler(event)">
 <s:layout>
  <s:HorizontalLayout/>
 </s:layout>
 
 <fx:Style>
  @namespace esri "http://www.esri.com/2008/ags";
  
  esri|Editor
  {
   skin-class: ClassReference("assets.skins.EditorSkin"); /* undo/redo buttons commented */
  }
 </fx:Style>
 
 <fx:Script>
  <![CDATA[   
   import com.esri.ags.components.Editor;
   import com.esri.ags.events.FeatureLayerEvent;
   import com.esri.ags.tasks.GeometryService;
   
   import mx.events.FlexEvent;
   
   private var myEditor:Editor;
   private var geometryService:GeometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
   
   protected function application_initializeHandler(event:FlexEvent):void
   {
    myEditor = new Editor();
    myEditor.map = myMap;
    myEditor.featureLayers = [ points, fireAreas ];
    myEditor.geometryService = geometryService;
    myEditor.toolbarVisible = true;
    
    editorHolder.addElement(myEditor);
   }

   protected function editsStartingHandler(event:FeatureLayerEvent):void
   {
    var addingDisabled:Boolean = Math.random() > 0.5;
    
    if (event.adds && event.adds.length > 0 && addingDisabled && event.cancelable)
    {
     event.preventDefault();
     
     editorHolder.removeAllElements();
     
     myEditor = new Editor();
     myEditor.map = myMap;
     myEditor.featureLayers = [ points, fireAreas ];
     myEditor.geometryService = geometryService;
     myEditor.toolbarVisible = true;
     
     editorHolder.addElement(myEditor);
    }
   }

  ]]>
 </fx:Script>
 
 <s:VGroup width="328" height="100%" id="editorHolder" />
 <esri:Map id="myMap" wrapAround180="true">
  <esri:extent>
   <esri:Extent id="sheepfire"
       xmin="-13144000" ymin="4033000" xmax="-13066000" ymax="4099000">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
  <esri:FeatureLayer id="fireAreas"
         editsStarting="editsStartingHandler(event)"
         mode="snapshot"
         outFields="*"
         url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/2"/>
  <esri:FeatureLayer id="points"
         mode="snapshot"
         editsStarting="editsStartingHandler(event)"
         outFields="*"
         url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0"/>
 </esri:Map> 
</s:Application>
0 Kudos
by Anonymous User
Not applicable
Original User: arslansai

i did it.
(EditorSkin)(myEditor.getChildAt(0)).currentState = "normal"

it is reset editor status to normal.
0 Kudos