Hi all,
I am trying to convert a working MXML application with a custom mapclick handler and an attribute table into the Flex Viewer so that I can take advantage of the better interface and widget capabilities--particularly the collapsable aspect of the attribute table widget.
My question is, what is the best practice for this to be done? Do I add a script block into the index.mxml part, or is it something I should be changing in configuration files? In my first attempt to add my script into the index.mxml file, I realized this wouldn't work because I had variables in my script referencing drop down lists in my control bar, etc.
Is it possible to get this to work correctly in the viewer?
Thank you so much for your advice.
-David
FYI I am working with Flash Builder 4.6, Flex Api 3.3, and ArcGIS Server 10.
My script is:
I am trying to convert a working MXML application with a custom mapclick handler and an attribute table into the Flex Viewer so that I can take advantage of the better interface and widget capabilities--particularly the collapsable aspect of the attribute table widget.
My question is, what is the best practice for this to be done? Do I add a script block into the index.mxml part, or is it something I should be changing in configuration files? In my first attempt to add my script into the index.mxml file, I realized this wouldn't work because I had variables in my script referencing drop down lists in my control bar, etc.
Is it possible to get this to work correctly in the viewer?
Thank you so much for your advice.
-David
FYI I am working with Flash Builder 4.6, Flex Api 3.3, and ArcGIS Server 10.
My script is:
Code:
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.tasks.supportClasses.Query;
import mx.collections.ArrayCollection;
import spark.events.IndexChangeEvent;
import com.esri.ags.Map;
//Create labels for drop down list data provider
[Bindable]
public var myDP:ArrayCollection = new ArrayCollection(
[ {timeframe:"Last 2 Weeks"},
{timeframe:"Last Month"},
{timeframe:"Last 6 Months"},
{timeframe:"Last Year"}]);
//Create string variable assigned initially to definition expression for last two weeks
[Bindable]
public var updateDefExp:String = "TIME_FRAME = 'TWO WEEKS'";
//Create functions to update definition expression in drop down list
private function doQuery0():void
{
var defExp0:String = "TIME_FRAME = 'TWO WEEKS'";
updateDefExp = defExp0;
}
private function doQuery1():void
{
var defExp1:String = "TIME_FRAME = '1 MONTH'";
updateDefExp = defExp1;
}
private function doQuery2():void
{
var defExp2:String = "TIME_FRAME = '6 MONTHS'";
updateDefExp = defExp2;
}
private function doQuery3():void
{
var defExp3:String = "TIME_FRAME = '1 YEAR'";
updateDefExp = defExp3;
}
//Create function to update the updateDefExp variable to the correct timeframe
private function updateSelection(e:IndexChangeEvent):void
{
if(myDDL.selectedIndex == 0)
{
myFeatureLayer.clearSelection();
doQuery0();
myMap.extent=myExtent;
}
else if (myDDL.selectedIndex == 1)
{
myFeatureLayer.clearSelection();
doQuery1();
myMap.extent=myExtent;
}
else if (myDDL.selectedIndex == 2)
{
myFeatureLayer.clearSelection();
doQuery2();
myMap.extent=myExtent;
}
else if (myDDL.selectedIndex == 3)
{
myFeatureLayer.clearSelection();
doQuery3();
myMap.extent=myExtent;
}
}
protected function myMap_clickHandler(event:MouseEvent):void
{
if (event.target is Graphic || event.target.parent is Graphic)
{
var graphic:Graphic = event.target is Graphic ? Graphic(event.target) : Graphic(event.target.parent);
var query:Query = new Query;
query.objectIds = [ graphic.attributes[myFeatureLayer.layerDetails.objectIdField]];
myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
myMap.zoomTo(graphic.geometry);
myMap.scale = 1000;
}
else
{
myFeatureLayer.clearSelection();
}
}
]]>
</fx:Script>