private function widgetCommunication1():void { addSharedData("your key", shared data(ArrayCollection)); }
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:viewer="com.esri.viewer.*" initialize="basewidget1_initializeHandler(event)" > <fx:Script> <![CDATA[ import com.esri.viewer.AppEvent; import mx.events.FlexEvent; protected function basewidget1_initializeHandler(event:FlexEvent):void { ViewerContainer.addEventListener(AppEvent.DATA_PUBLISH, sharedDataUpdated); } private function sharedDataUpdated(event:AppEvent):void { var data:Object = event.data; if (data.key == "my key") { // do something.. } } ]]> </fx:Script>
public static const REFRESH_MY_WIDGET_NR_2:String = "refreshMyWidgetNr2";
AppEvent.addListener(AppEvent.REFRESH_MY_WIDGET_NR_2, widgetRefreshHandler, false, 1); ... private function widgetRefreshHandler(event:AppEvent):void { // right place to refresh // read sended data // var sendedData:Object = event.data; }
var sendedData:Object = null; AppEvent.dispatch(AppEvent.REFRESH_MY_WIDGET_NR_2, sendedData);
// in script tag [Bindable] private var objid:Number; // in some function when object id changed objid = somevalue; // in declaration tag <esri:Query id="query" outFields="" returnGeometry="false" where="OBJECTID={objid}"/>
// in some function when object id changed query.where = StringUtil.substitute("OBJECTID={0}", somevalue); // in declaration tag <esri:Query id="query" outFields="" returnGeometry="false" />
Here was similar task.And here is other way to do it.
<esri:Query id="query" outFields="" returnGeometry="false" where="OBJECTID={objid}"/>
recAC.addItem(obj.OBJECTID); addSharedData("HelloWorldWidget", recAC);
AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated); AppEvent.addListener(AppEvent.DATA_SENT, sharedDataUpdated);
private function sharedDataUpdated(event:AppEvent):void { var data:Hashtable = event.data as Hashtable; Alert.show("Length is "+data); if (data.containsKey("HelloWorldWidget")) { var myAC:ArrayCollection =data.find("HelloWorldWidget") as ArrayCollection; Alert.show("Length is "+myAC.length); } }
AppEvent.dispatch(AppEvent.WIDGET_RUN, ViewerContainer.getInstance().getWidgetId("WIDGET_NAME"));
ViewerContainer.addEventListener(AppEvent.DATA_SENT, sharedDataUpdated);
//call the range detail widget. ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getInstance().getWidgetId("Range Detail"))); //add the ArrayCollection data to the sharedData object on the BaseWidget class. addSharedData("ArtyDetail", rangeDetailArray);
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:viewer="com.esri.viewer.*" xmlns:customValidators="Landmarc.customValidators.*" initialize="myBaseWidgetInitHandler(event)" widgetConfigLoaded="init()" xmlns:supportClasses="com.esri.ags.skins.supportClasses.*"> protected function myBaseWidgetInitHandler(event:FlexEvent):void { ViewerContainer.addEventListener(AppEvent.DATA_PUBLISH, sharedDataUpdated); } public function sharedDataUpdated(event:AppEvent):void { var data:Object = event.data; switch (data.key) { //if arty detail there is a maximum of 2 items in the ArrayCollection. First is the grids, second (if present) is the direct fire firing point case "ArtyDetail": { txtSta.text = data.collection[0].toString(); //if the artillery selection was a direct fire, then there will be a firing position in the second item in the collection if (data.collection[1]) { txtWeaponPosition.text = data.collection[1].toString(); } break; }
protected function editButton_clickHandler(event:MouseEvent):void { ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getInstance().getWidgetId("Edit"))); }
<?xml version="1.0" encoding="utf-8"?> <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags" xmlns:Search="widgets.Response.*" xmlns:viewer="com.esri.viewer.*" widgetConfigLoaded="init()"> <fx:Script> <![CDATA[ import com.esri.viewer.ViewerContainer; import com.esri.viewer.AppEvent; import mx.controls.Alert; private var viewerCon:ViewerContainer; //this function called when the widget's configuration is loaded private function init():void { } protected function editButton_clickHandler(event:MouseEvent):void { ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, viewerCon.getWidgetId("Edit"))); } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <viewer:WidgetTemplate id="Removal" width="450" height="180"> <mx:Button id="editButton" label="Edit" click="editButton_clickHandler(event)"/> </viewer:WidgetTemplate> </viewer:BaseWidget>
Anthony, All you have to do is call ViewerContainer.getInstance()
ViewerContainer.getInstance()
trace(viewerCon.getWidgetId("Selection"));
Alert.show(viewerCon.getWidgetId("Selection"));
viewerCon:ViewerContainer = ViewerContainer.getInstace(); // inside init() ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, viewerCon.getWidgetId("Selection") ) ); AND ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getInstance().getWidgetId("Selection") ) );
Bob, You have to know your widgets Id number. The widgets id is not a string it is a sequential number that is assigned when the widget is created in FlexViewer.Here is the code:ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, yourWidgetsID#));I added a new function to the ViewerContainer.mxml for the purpose of finding a widgets id # //Add this new variable at the beginning with the other private and public vars public var _configData:ConfigData; //Add this new function public function getWidgetId(widgetLabel:String):Number { var id:Number; for (var i:Number = 0; i < _configData.widgets.length; i++) { if (_configData.widgets.label == widgetLabel) id = _configData.widgets.id; } return id; } //Add this to the postConfigHandler function _configData = event.data as ConfigData; Then you can do something like thisViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getWidgetId("Search")));
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, yourWidgetsID#));
//Add this new variable at the beginning with the other private and public vars public var _configData:ConfigData; //Add this new function public function getWidgetId(widgetLabel:String):Number { var id:Number; for (var i:Number = 0; i < _configData.widgets.length; i++) { if (_configData.widgets.label == widgetLabel) id = _configData.widgets.id; } return id; } //Add this to the postConfigHandler function _configData = event.data as ConfigData;
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, ViewerContainer.getWidgetId("Search")));
Widget 1 private function widgetCommunication1():void { addSharedData("your key", shared data(ArrayCollection)); } Widget 2 <viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:viewer="com.esri.viewer.*" initialize="basewidget1_initializeHandler(event)" > <fx:Script> <![CDATA[ import com.esri.viewer.AppEvent; import mx.events.FlexEvent; protected function basewidget1_initializeHandler(event:FlexEvent):void { ViewerContainer.addEventListener(AppEvent.DATA_PUBLISH, sharedDataUpdated); } private function sharedDataUpdated(event:AppEvent):void { var data:Object = event.data; if (data.key == "my key") { // do something.. } } ]]> </fx:Script> Hope that helps.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.