Hello all,I was curious if anyone has had any success converting on of the BA server example applications into a widget.I'm currently playing with the example linked below, and am not having success turning it into a functioning widget. I would appreciate any help along those lines. I've been trying to complete the task by copying off of another working widget and haven't had any luck yet. My code is below, and the original code is available at the link for anyone who could volunteer to take a look. http://help.arcgis.com/en/businessanalyst/10.0/server/apis/flex/samples/index.html?sample=DriveTimeIs there any step by step available for doing this, or even a help page explicitly explaining how a widget and application differ?Thanks in advance for any help!Note: I cut out my imports because I had to reduce the number of characters.<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
widgetConfigLoaded="init()">
<fx:Script>
<![CDATA[
//----------------------------------
// Internal variables
//----------------------------------
// Bindable array for reports list
[Bindable]private var _reports : Array;
// drawn map point object
private var _point : MapPoint;
// Initial map extent.
private var _initialExtent : Extent;
//----------------------------------
// Initializing
//----------------------------------
/**
* Initialize the sample and activate the draw toolbar.
*/
private function init():void
{
drawToolbar.activate(DrawTool.MAPPOINT);
}
protected function report_openHandler(event:Event):void
{
map.addEventListener(MapMouseEvent.MAP_CLICK,mapClickHandler)
map.addLayer(myGraphicsLayer);
}
protected function report_closedHandler(event:Event):void
{
clear();
//map.removeLayer(myGraphicsLayer);
map.removeEventListener(MapMouseEvent.MAP_CLICK,mapClickHandler)
}
private function clear():void
{
myGraphicsLayer.clear();
}
private function mapClickHandler(event:MapMouseEvent):void
{
onDrawEnd(event.mapPoint);
}
//----------------------------------
// Drawing
//----------------------------------
/**
* Event handler for draw completing event;
* capture the graphics from draw toolbar,
* add the graphics to the Map and create an object
* based on the graphic drawn.
*/
private function onDrawEnd(event:DrawEvent):void
{
var graphic:Graphic = event.graphic;
// clear the previous drawing
gLayer1.clear();
gLayer1.add(graphic);
// Capture the point geometry from the draw toolbar.
if(event.graphic.geometry is MapPoint)
_point = MapPoint(event.graphic.geometry);
drawToolbar.deactivate();
executeTask();
map.extent = _initialExtent;
}
//----------------------------------
// Executing the task
//----------------------------------
/**
* Executes the task.
*/
private function executeTask():void
{
if(_point)
{
//create the parameters used by this task
var params : DriveTimeParameters = createParameters();
//Get a static reference to a singleton instance of the BAServerClient class.
//Instructions for how to create the BAServerClient class is provided at the top of this file.
var client : BAServerClient = new BAServerClient();
client.url = "http://nsesribap01vmsean:80/ArcGIS/baserver/REST/services/DefaultMap/BAServer";
var task : DriveTimeTask = new DriveTimeTask(client);
task.execute(params, new mx.rpc.Responder(resultHandler, faultHandler));
}
else
{
Alert.show("Store The point is not set.");
}
}
/**
* Creates parameters of the task.
*/
private function createParameters() : DriveTimeParameters
{
//task output type
var outputTypes : OutputTypes = new OutputTypes();
outputTypes.getFeatureClass = true;
outputTypes.getReport = true;
var params : DriveTimeParameters = new DriveTimeParameters(outputTypes);
//distance units
params.distanceUnits = DriveTimeUnits.DRIVE_MINUTES;
//radii
params.radii = [3,5,10];
//create stores
var pointLayer : PointLayer =
new PointLayer([ new PointRecord("Store 1", "Redlands", "1", _point.y, _point.x)]);
params.stores = pointLayer;
//donut
params.donut = false;
//report options
params.reportOptions = [
new ReportOptions("PDF", "Market Profile", new BAReportHeader("Market Profile"))
];
return params;
}
/**
* Result handler for the successful completion of the task execution.
*/
private function resultHandler(event:BATaskCompletedEvent, token:Object=null):void
{
var taskResultOutput : TaskResultOutput = event.result as TaskResultOutput;
//draw the features on the map
var fs : FeatureSet = taskResultOutput.recordSet;
if (fs)
{
// add the resulting features to the map
for (var i:Number = 0; i < fs.features.length; i++)
{
var g : Graphic = fs.features;
// set tooltip from attributes
g.toolTip = fs.features.attributes["AREA_DESC2"];
g.autoMoveToTop = false;
gLayer.add(g);
}
zoomToExtent();
}
//print out the report information
_reports = [];
for each(var item : ReportInfo in taskResultOutput.reports)
{
var rep : Object = new Object();
rep["templateName"] = item.templateName;
rep["format"] = item.format;
rep["url"] = item.url;
rep["text"] = "Open Report";
_reports.push(rep);
}
}
/**
* Generalized fault handler for an asynchronous failed task execution.
*/
private function faultHandler(event:FaultEvent, token:Object=null):void
{
var message:String = "An error occurred while executing the underlying Web Service request.";
message += " Please try again later.";
Alert.show(message, "Error");
}
/**
* Event handler function for grid double click event
* Handle opening the report when the 'Open Report' button is double clicked
*/
private function onGridDoubleClick(e:ListEvent):void
{
var url:String = e.itemRenderer.data.url;
navigateToURL(new URLRequest(url), "_blank");
}
/**
* Zoom to the resulting features extent
*/
private function zoomToExtent() : void
{
var allGraphics : Array = gLayer.graphicProvider.source as Array;
allGraphics = allGraphics.concat(gLayer1.graphicProvider.source as Array);
map.extent = GraphicUtil.getGraphicsExtent(allGraphics).expand(1.25);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Control to user draw -->
<esri:DrawTool id="drawToolbar"
map="{map}"
markerSymbol="{sMarker}"
drawEnd="onDrawEnd(event)" />
<!-- Set the marker symbol for user draw -->
<esri:SimpleMarkerSymbol id="sMarker" color="0xFFFF00" size="15" style="circle">
<esri:SimpleLineSymbol color="0x000000" width="2"/>
</esri:SimpleMarkerSymbol>
<!-- Set renderer for Drive Time output feature class -->
<esri:SimpleFillSymbol id="bFill" alpha="0.5" color="0x0000FF"/>
<esri:SimpleFillSymbol id="gFill" alpha="0.5" color="0x00FF00"/>
<esri:SimpleFillSymbol id="rFill" alpha="0.5" color="0xFF0000"/>
<esri:UniqueValueRenderer id="uniqueValueRenderer" attribute="RING">
<esri:UniqueValueInfo value="1" symbol="{rFill}"/>
<esri:UniqueValueInfo value="2" symbol="{gFill}"/>
<esri:UniqueValueInfo value="3" symbol="{bFill}"/>
</esri:UniqueValueRenderer>
</fx:Declarations>
<viewer:WidgetTemplate id= "report"
width="305"
height="100"
open="report_openHandler(event)"
closed="report_closedHandler(event)"/>
<mx:VDividedBox width="100%" height="100%">
<!-- Map control -->
<esri:Map id="map">
<esri:extent>
<esri:Extent xmin="-117.352" ymin="33.955" xmax="-117.023" ymax="34.167">
<esri:SpatialReference wkid="4326"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
<!-- Graphics Layer to draw resulting features-->
<esri:GraphicsLayer id="gLayer" renderer="{uniqueValueRenderer}" />
<!-- Graphics Layer to draw user input-->
<esri:GraphicsLayer id="gLayer1"/>
</esri:Map>
<s:VGroup width="100%" height="30%">
<s:Label text="Reports" fontWeight="bold"/>
<!-- Grid to display the list of reports -->
<mx:DataGrid
dataProvider="{_reports}" doubleClickEnabled="true" itemDoubleClick="onGridDoubleClick(event)"
scroll="true" width="100%" height="90%" textAlign="center">
<mx:columns>
<mx:DataGridColumn dataField="templateName" headerText="Template Name"/>
<mx:DataGridColumn headerText="URL" color="0x0000FF" dataField="text"/>
<mx:DataGridColumn dataField="format" headerText="Format"/>
<mx:DataGridColumn dataField="url" visible="false"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</mx:VDividedBox>
</viewer:BaseWidget>