Select to view content in your preferred language

Change FlexViewer widget icon and label programmatically

4347
4
Jump to solution
02-29-2012 10:31 AM
BradleyMontgomery
Emerging Contributor
In the sample Flexviewer, I'm using one widget to pop up another one using the PopupManager. I want to set the new widgets icon and title using the 'widgetIcon' and 'widgetTitle' properties but nothing I enter changes the default icon or enters a title. In fact, changing those properties in one of the standard widgets doesn't change anything either. How do I change the icon and title/label for a widget from within code.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Charile,

   This is what I tested and it work fine:

<?xml version="1.0" encoding="utf-8"?> <!-- /////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010-2011 Esri. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // //    http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////////// --> <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:viewer="com.esri.viewer.*"                    widgetConfigLoaded="init()">     <fx:Script>         <![CDATA[             //this function called when the widget's configuration is loaded             private function init():void             {                 if (configXML) // checking for valid content in the configuration file                 {                     lbl.text = configXML.content || getDefaultString("helloContent");                 }             }                          protected function button1_clickHandler(event:MouseEvent):void             {                 helloWorld.widgetTitle = "This is my changed Title...";                 helloWorld.widgetIcon = "assets/images/i_clock.png";             }                      ]]>     </fx:Script>     <viewer:WidgetTemplate id="helloWorld"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>          <s:Label id="lbl"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>         <s:Button click="button1_clickHandler(event)" label="change" />     </viewer:WidgetTemplate> </viewer:BaseWidget>

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Charlie,

   A couple of things you might want to note...

This is the Flex API Forum and not The Flex Viewer and or widgets forum which you can find here:

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

Next just FYI. Since version 2.x the viewer has been a supported esri product and hence is not the Sample Flex Viewer anymore it is the Flex Viewer.

To answer you question though you need to set the widgetTitle and WidgetIcon on the WidgetTemplate and not the BaseWidget.

Don't forget to click the Mark as answer check and to click the top arrow (promote) as shown below:
0 Kudos
BradleyMontgomery
Emerging Contributor
Thanks Robert. Sorry for posting in the wrong place. I don't do this very often. Anyway, I'm already trying to set those properties in the WidgetTemplate but the settings don't take:

<viewer:WidgetTemplate id="queryTemplate" backgroundAlpha="1" width="524" widgetTitle="Some Title" widgetIcon="assets.DNR.images.40x40_widget.i_search.png" height="300" skinClass="com.esri.viewer.skins.WidgetTemplateSkin">
  <mx:Canvas id="dgCanvas" height="100%" width="100%" visible="true">
  <mx:HBox horizontalAlign="center" width="100%" height="100%" >  
   <mx:AdvancedDataGrid id="queryGrid" height="100%" wordWrap="true" rowHeight="20" alternatingItemColors="[#FFFFFF, #EEEEEE]" fontSize="10" >
   </mx:AdvancedDataGrid>
  </mx:HBox>
  </mx:Canvas>
</viewer:WidgetTemplate>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Charile,

   This is what I tested and it work fine:

<?xml version="1.0" encoding="utf-8"?> <!-- /////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010-2011 Esri. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // //    http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /////////////////////////////////////////////////////////////////////////// --> <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:viewer="com.esri.viewer.*"                    widgetConfigLoaded="init()">     <fx:Script>         <![CDATA[             //this function called when the widget's configuration is loaded             private function init():void             {                 if (configXML) // checking for valid content in the configuration file                 {                     lbl.text = configXML.content || getDefaultString("helloContent");                 }             }                          protected function button1_clickHandler(event:MouseEvent):void             {                 helloWorld.widgetTitle = "This is my changed Title...";                 helloWorld.widgetIcon = "assets/images/i_clock.png";             }                      ]]>     </fx:Script>     <viewer:WidgetTemplate id="helloWorld"                            width="300" height="300">         <viewer:layout>             <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>         </viewer:layout>          <s:Label id="lbl"                  fontSize="18"                  fontStyle="italic"                  fontWeight="bold"/>         <s:Button click="button1_clickHandler(event)" label="change" />     </viewer:WidgetTemplate> </viewer:BaseWidget>
0 Kudos
BradleyMontgomery
Emerging Contributor
Well Robert, once again you come to the rescue. It had to do with where I was trying to set the widgetIcon and widgetTitle. It has no effect when you set it in the WidgetTemplate definition. You have to set it in the script body referencing the ID of the the widget template. Silly me for assuming you could set it in the widgetTemplate definition.

Thanks SO MUCH!
0 Kudos