Select to view content in your preferred language

trouble passing data between widgets

4274
16
08-16-2011 06:19 AM
WadeGivens
Emerging Contributor
I have a custom query tool that was developed for me, and I would like to pass 2 combobox selections to a print widget to use as the title of a print template in a print widget.  I have taken a look at the post where Robert explained how to do this (http://forums.arcgis.com/threads/13863-Communication-between-widgets?highlight=widget+communication), but I still seem to be having a bit trouble.  the code I have put together is below.  I think the problem may be in how I'm building my array in the custom query widget and/or how I'm trying to recall the items in the array in my print widget.  Any suggestions out there?


// CUSTOM QUERY WIDGET

// share data
var layoutArr:ArrayCollection = new ArrayCollection();   
layoutArr.addItemAt(String(cboLayerHybrid.selectedLabel), 0);
layoutArr.addItemAt(String(cboLayerTrait.selectedLabel), 1);
addSharedData("LayoutTitle", layoutArr);

// CUSTOM PRINT WIDGET

private function init():void
    {
 trace("MyPrintWidget init()");
 AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
    }
   
private function sharedDataUpdated(event:AppEvent):void
    {
        var data:Object = event.data;    
        if (data.key == "LayoutTitle")
 
        {
            var theObj:Object = data.collection[0];
            layoutArr.addItem(theObj);
            mapproduct = layoutArr.getItemAt(0);
            maptrait = layoutArr.getItemAt(1);
            title = mapproduct + maptrait;
        }
    }



Thanks,
Wade
Tags (2)
0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus
Wade,

   Be sure to post Flex Viewer Questions to the Flex Viewer forum...

http://forums.arcgis.com/forums/111-ArcGIS-Viewer-for-Flex

I try this instead:

// share data
var layoutArr:ArrayCollection = new ArrayCollection();
var printConfig:Object = {
    mapproduct: String(cboLayerHybrid.selectedLabel),
    maptrait: String(cboLayerTrait.selectedLabel)
};            
layoutArr.addItem(printConfig);
addSharedData("LayoutTitle", layoutArr);

    private function sharedDataUpdated(event:AppEvent):void
    {
        var data:Object = event.data;                
        if (data.key == "LayoutTitle")
        {
            var theObj:Object = data.collection[0];
            mapproduct = theObj.mapproduct;
            maptrait = theObj.maptrait;
            title = mapproduct + maptrait;
        }
    }
0 Kudos
WadeGivens
Emerging Contributor
Thanks Robert. Sorry for posting in this forum. Can't ever keep it straight of which to post which questions in. I've got that code implemented and it runs with no errors, but it's not populating a text box with the values when I save them in my title:String variable (highlighted in dark red).


   
   private function init():void
   {
    trace("MyPrintWidget init()");
    AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
   }
   
   private function sharedDataUpdated(event:AppEvent):void
   {
    var data:Object = event.data;    
    if (data.key == "LayoutTitle")
    {
     var theObj:Object = data.collection[0];
     mapproduct = theObj.mapproduct;
     maptrait = theObj.maptrait;
     title = mapproduct + maptrait;
    }
   }
   
 
   
   private function widgetClosedHandler(event:Event):void
   {
    graphicsLayer.visible = false;
    setMapNavigation(null, null);
   }  
   
   private function widgetMinimizedHandler(event:Event):void
   {
    this.widgetClosedHandler(event); 
   }
   
   private function widgetOpenedHandler(event:Event):void
   {
    graphicsLayer.visible = true; 
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:SimpleFillSymbol id="sfs" color="0xE95020" alpha="1" style="solid">
   <esri:SimpleLineSymbol color="0xFF0000" width="4" alpha="1" style="solid" />
  </esri:SimpleFillSymbol>
  <esri:GraphicsLayer id="graphicsLayer" symbol="{sfs}"/>
 </fx:Declarations>
 <viewer:WidgetTemplate id="wTemplate"
         closed="widgetClosedHandler(event)" 
         open="widgetOpenedHandler(event)"
         minimized="widgetMinimizedHandler(event)"
         skinClass="com.esri.viewer.skins.WidgetTemplateSkin"
         width="260" height="134">
  s:VGroup width="100%" height="100%" verticalAlign="top" horizontalAlign="center"> 
   <mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="86">
    <<s:HGroup horizontalAlign="center" width="100%" verticalAlign="middle">
     <mx:Text id="labelTxt" text="Map Title: " textAlign="right"/>
     <s:TextInput id="input" text="{title}"/>
    </s:HGroup>
    <s:HGroup horizontalAlign="center" width="100%">
     <s:Button label="Print Preview" click="landscapePrintPreview()"/>
    </s:HGroup>
   </mx:Form>
  </s:VGroup>
 </viewer:WidgetTemplate>

</viewer:BaseWidget>


Thanks,
Wade
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wade,

  Can you post your whole print widget mxml?
0 Kudos
WadeGivens
Emerging Contributor
<?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" 
   xmlns:mxeffects="com.adobe.ac.mxeffects.*"
   xmlns:flash="flash.text.*"
   xmlns:viewer="com.esri.viewer.*"
   xmlns:widgets="widgets.*"
   x="600" y="300"
   widgetConfigLoaded="init()">
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.Graphic;
   import com.esri.ags.Map;
   import com.esri.ags.events.GeometryServiceEvent;
   import com.esri.ags.layers.GraphicsLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.ags.symbols.SimpleFillSymbol;
   import com.esri.ags.symbols.SimpleLineSymbol;
   import com.esri.viewer.ViewerContainer;
   import com.esri.viewer.AppEvent;
   
   import flash.display.Sprite;
   import flash.net.SharedObject;
   import flash.printing.PrintJob;
   import flash.text.TextField;
   
   import mx.collections.ArrayCollection;
   import mx.containers.Canvas;
   import mx.controls.Alert;
   import mx.controls.Image;
   import mx.core.UIComponent;
   import mx.graphics.ImageSnapshot;
   import mx.graphics.codec.JPEGEncoder;
   import mx.graphics.codec.PNGEncoder;
   import mx.managers.CursorManager;
   import mx.managers.PopUpManager;
   
   import widgets.myPrint.PrintPreview;
   import widgets.myPrint.layouts.A5_Landscape;
   import widgets.myPrint.utils.PrintMapUtil;

   
   //labels
   [Bindable]
   private var image:Image;
   
   [Bindable]
   private var graphic:Graphic;
   [Bindable]
   private var title:String;

   [Bindable]
   private var titleLabel:String;
   
   [Bindable]
   private var mapproduct:String;
   [Bindable]
   private var maptrait:String;
   
   private function init():void
   {
    trace("MyPrintWidget init()");
    AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
   }
   
   private function sharedDataUpdated(event:AppEvent):void
   {
    var data:Object = event.data;    
    if (data.key == "LayoutTitle")
    {
     var theObj:Object = data.collection[0];
     mapproduct = theObj.mapproduct;
     maptrait = theObj.maptrait;
     title = mapproduct + maptrait;
    }
   }
   
 
   private function landscapePrintPreview():void
   {
    graphicsLayer.clear();
    // create instance of our map layout
    var mapLayout:A5_Landscape = new A5_Landscape();
    mapLayout.initialize();
    mapLayout.map = map;
    mapLayout.inputTxt.text = title;    
    
    // Create the popup and set its map layout 
    var popup:PrintPreview = PrintPreview(PopUpManager.createPopUp(map,PrintPreview,false));
    popup.mapLayout = mapLayout;
   }
   
   private function imageHandler(image:Image):void 
   {
    map.zoomSliderVisible = false;
    map.scaleBarVisible = false;
    
    var graphic:Graphic = PrintMapUtil.trimmedExtent(map,
     image.width,
     image.height);
    graphicsLayer.clear();
    graphicsLayer.add(graphic);
    
    image.source = PrintMapUtil.trimmedMap(map,
     image.width,
     image.height);
    map.zoomSliderVisible = false;
    map.scaleBarVisible = false;
   }
   
   private function widgetClosedHandler(event:Event):void
   {
    graphicsLayer.visible = false;
    setMapNavigation(null, null);
   }  
   
   private function widgetMinimizedHandler(event:Event):void
   {
    this.widgetClosedHandler(event); 
   }
   
   private function widgetOpenedHandler(event:Event):void
   {
    graphicsLayer.visible = true; 
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:SimpleFillSymbol id="sfs" color="0xE95020" alpha="1" style="solid">
   <esri:SimpleLineSymbol color="0xFF0000" width="4" alpha="1" style="solid" />
  </esri:SimpleFillSymbol>
  <esri:GraphicsLayer id="graphicsLayer" symbol="{sfs}"/>
 </fx:Declarations>
 <viewer:WidgetTemplate id="wTemplate"
         closed="widgetClosedHandler(event)" 
         open="widgetOpenedHandler(event)"
         minimized="widgetMinimizedHandler(event)"
         skinClass="com.esri.viewer.skins.WidgetTemplateSkin"
         width="260" height="134">
  <s:VGroup width="100%" height="100%" verticalAlign="top" horizontalAlign="center"> 
   <mx:Form id="frmPrint" verticalScrollPolicy="off" paddingBottom="0" width="100%" height="86">
    <s:HGroup horizontalAlign="center" width="100%" verticalAlign="middle">
     <mx:Text id="labelTxt" text="Map Title: " textAlign="right"/>
     <s:TextInput id="input" text="{title}"/>
    </s:HGroup>
    <s:HGroup horizontalAlign="center" width="100%">
     <s:Button label="Print Preview" click="landscapePrintPreview()"/>
    </s:HGroup>
   </mx:Form>
  </s:VGroup>
 </viewer:WidgetTemplate>

</viewer:BaseWidget>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wade,

   I have no problem changing the title in my test environment I set up for this. Are you possibly sending the addSharedData before the print widget is initialized?
0 Kudos
WadeGivens
Emerging Contributor
Wade,

   I have no problem changing the title in my test environment I set up for this. Are you possibly sending the addSharedData before the print widget is initialized?


Where would I check that?

Wade
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wade,

   Is your print widget set to preload? is it open in your app before the addSharedData function is called?
0 Kudos
WadeGivens
Emerging Contributor
I just checked that and changed it to preload.  Cleared my cache as well.  No luck.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wade,

   Have you tried putting a breakpoint in the sharedDataUpdated function and launched the app in debug instead of the standard run(little green bug to the left of the play button in flash builder)?
0 Kudos