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>
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")));
<script type="text/javascript"> function getFlexApp(appName) { if (navigator.appName.indexOf ("Microsoft") !=-1) { return window[appName]; } else { return document[appName]; } } function someFlexFunction() { getFlexApp('index').flexTalk('Hello World'); } </script> <input type="button" id="butFlexTalk" onclick="someFlexFunction()" value="Say Hello" />
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:viewer="com.esri.viewer.*" xmlns:managers="com.esri.viewer.managers.*" pageTitle="ArcGIS Viewer for Flex" initialize="initApp()"> <fx:Script> <![CDATA[ import mx.controls.Alert; public function initApp():void { if (ExternalInterface.available) ExternalInterface.addCallback("flexTalk", flexTalk); } public function flexTalk(sayThis:String):void { Alert.show(sayThis); } ]]> </fx:Script> <fx:Style source="defaults.css"/>
ViewerContainer.addEventListener(AppEvent.DATA_SENT, sharedDataUpdated); private function sharedDataUpdated(event:AppEvent):void { var dataTable:Hashtable = event.data as Hashtable; if (dataTable.containsKey("ParcelAddress")) { var recAC:ArrayCollection = dataTable.find("ParcelAddress") as ArrayCollection; for (var i:Number = 0; i < recAC.length; i++) { var obj:Object = recAC; var fitm:* = frmLocateAddress.getChildAt(0); var tAddress:TextInput = fitm.getChildAt(0) as TextInput; tAddress.text = obj.paddress; showStateAddress(); } dataTable.remove("ParcelAddress"); } }
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.
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.getInstance()
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") ) );
trace(viewerCon.getWidgetId("Selection"));
Alert.show(viewerCon.getWidgetId("Selection"));
Anthony, All you have to do is call ViewerContainer.getInstance()
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.