Solved! Go to Solution.
var OIDArr:Array = new Array; for(anX=0;anX<targetLayer.selectedFeatures.length;anX++){ Alert.show(targetLayer.selectedFeatures[anX].attributes[targetLayer.layerDetails.objectIdField]) }
protected function InvertSelBtn_clickHandler(event:MouseEvent):void{ var i:Number = new Number; //array to hold selected features (graphics) in target layer var selected:Array = []; for(i=0;i<targetLayer.selectedFeatures.length;i++){ var graphic:Graphic = targetLayer.selectedFeatures; selected.push(graphic); } //clear selected features in targetLayer after selected in loaded with the features that were selected targetLayer.clearSelection(); Alert.show("before loading all features"); //this holds all features in the targetLayer var targetLayerFeatures:ArrayCollection = new ArrayCollection; targetLayerFeatures = targetLayer.graphicProvider as ArrayCollection; Alert.show(targetLayerFeatures.contains(selected[1]).toString());
protected function InvertSelBtn_clickHandler(event:MouseEvent):void{ var i:Number = new Number; var marker:Boolean = false; //holds all features in the targetLayer var features:Array = []; //holds all currently selected features in targetLayer var selected:Array = []; //holds all features that are not currently selected - to be selected var notSelected:Array = []; //add features that are currently selected to array selected, then clear selection for(i=0;i<targetLayer.selectedFeatures.length;i++){ var selFeature:Graphic = targetLayer.selectedFeatures; selected.push(selFeature); } //last query selects all points targetLayer.clearSelection(); //this selects all features var query:Query = new Query; query.where = "1=1"; //this.cursorManager.setBusyCursor(); targetLayer.selectFeatures(query,"new",new AsyncResponder(onResult, onFault)); //if select all fails function onFault(info:Array, token:FeatureLayer = null):void{ Alert.show("Error During Invert Selection."); } //if selection is successful function onResult(info:Array, token:FeatureLayer = null):void{ //upon result of selecting all features, add all features from targetLayer to array features, then clear selection for(i=0;i<targetLayer.selectedFeatures.length;i++){ var feature:Graphic = targetLayer.selectedFeatures; features.push(feature); } //targetLayer.clearSelection(); //nested for loop to iterate through features (run once for each feature in targetLayer) //then iterate through selected (run once for each feature in selFeatures) //if their objects match, marker set to true - if at the end of the inside loop marker is still false //no match was found and for(x=0;x<features.length;x++){ for(y=0;y<selected.length;y++){ //if there is ever a match, mark boolean as true, and featureswont be added to notSelected //i will have to change this to work with line, poly -for now points is fine if(features .geometry as MapPoint === selected .geometry as MapPoint){ marker=true; } } //if match wasnt found in inside for loop, then the feature wasnt selected and will be added to notSelected if(marker===false){ notSelected.push(features ); } //speed things up and break the loop if all non selected features have been added if(features.length<=(selected.length+notSelected.length)){ break; } } //this alert broke the selection screen for some reason lol //Alert.show("# features selected: " +selected.length.toString()+"+ # features not selected: "+notSelected.length.toString()+"= # features total: "+features.length.toString()); //loop through notSelected, adding each feature in it to selection of targetLayer targetLayer.clearSelection(); Alert.show(notSelected.length.toString()); var query1:Query = new Query; query1.geometry = notSelected.geometry; query1.spatialRelationship=Query.SPATIAL_REL_OVERLAPS; targetLayer.selectFeatures(query1,"new",null); Alert.show(targetLayer.selectedFeatures.length.toString()); } }