I think it might not have to do with the lenght of the array collection. When I add another if clause ( else if (ac.length == 3)), that filter that I had before (when I typed "ref" and filtered two values to the array collection) stopped working. So it might have to do with the creation of another variable actually. I noticed that if I don't create qText4, then the filter for the two values work. So maybe the function is not executing anymore since when it filters to two values, it cannot get the third value and it therefore cannot create that 3rd variable that goes in the if clause. Do you have any idea why this is happening? Thanks!
private function doSearch():void
{
myAttributeTable.refresh();
myAttributeTable.visible = false
ac = new ArrayCollection();
ac.addItem({name:"Alpine",code:"AL"});
ac.addItem({name:"Austin",code:"AU"});
ac.addItem({name:"Referral - Consulting Forester",code:"RC"});
ac.addItem({name:"Referral Vendor", code:"RV"});
ac.addItem({name:"Incidental Rural Forestry",code:"AIR"});
ac.addItem({name:"Prevention and Reduction of Pest Losses",code:"AP"});
ac.addItem({name:"Forest Health Monitoring - Survey",code:"FHS"});
myAttributeTable.featureLayer = myFeatureLayer
myAttributeTable.featureLayer = yourTable
myAttributeTable.visible = true
ac.filterFunction = filter;
ac.refresh()
var itemname:String = ac.getItemAt(0).name
Alert.show(itemname)
var itemname1:String = ac.getItemAt(1).name
Alert.show(itemname1)
var qText2:String = ac.getItemAt(0).code
var qText3:String = ac.getItemAt(1).code
var qText4:String = ac.getItemAt(2).code
Alert.show(qText2)
Alert.show(qText3)
yourTable.refresh()
if (ac.length == 1)
{
Alert.show("TEST AC LENGTH 1")
var defexpr:String = searchattribute + "like" + "'" + qText2 + "'";
yourTable.definitionExpression = defexpr
}
else if (ac.length == 2)
{
Alert.show("TEST AC LENGTH 2")
var defexpr2:String = searchattribute + eqsymbol + "'" + qText2 + "'" + " OR " + searchattribute + eqsymbol + "'" + qText3 + "'";
yourTable.definitionExpression = defexpr2
myAttributeTable.featureLayer = yourTable
myAttributeTable.visible = true
}
else if (ac.length == 3)
{
Alert.show("TEST AC LENGTH 3")
var defexpr3:String = searchattribute + eqsymbol + "'" + qText2 + "'" + " OR " + searchattribute + eqsymbol + "'" + qText3 + "'" + " OR " + searchattribute + eqsymbol + "'" + qText4 + "'";
yourTable.definitionExpression = defexpr3
Alert.show(defexpr3)
myAttributeTable.featureLayer = yourTable
myAttributeTable.visible = true
}
else if (ac.length > 2)
{
Alert.show("TEST AC LENGTH ELSE")
myAttributeTable.visible = false
Alert.show("Please review your search and try again")
}
}