Get "UI" Widget by Id / Label

386
7
Jump to solution
04-30-2012 07:48 AM
Drew
by
Occasional Contributor III
Does teh ESRI Flex Viewer (2.5 +) have any code to get a "UI" widget by Label or ID.

i.e: I want access to the header widget from another widget.

Thanks,

Drew
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Drew
by
Occasional Contributor III
Here is my solution...

In the widgetManager.mxml file i had to make the variable "controlContainer" public and added my own function...

                        //=====================================================================    // Get UI Widget by Label.....,. (Make controlContainer PUBLIC)    //=====================================================================    public function getUIWidget(widgetLabel:String):IBaseWidget    {     for (var x:Number = 0; x < controlContainer.numElements; x++)     {      var widget:IBaseWidget = controlContainer.getElementAt(x) as IBaseWidget;      if (widget.widgetTitle.toUpperCase() == widgetLabel.toUpperCase())       return widget;     }          return null;    }


Drew

View solution in original post

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Drew,

   Have you tried giving it a label in the main config and using the standard:

ViewerContainer.getInstance().widgetManager.getWidgetId("HeaderControllerLabel")


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:

0 Kudos
Drew
by
Occasional Contributor III
I did try that method before and retested again, but it gives NaN when i try and get a UI element widget.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Drew,

   OK I see the issue... You need to replace your WidgetManager.mxml  getWidgetId function with this one.

/**
             * @return Returns the widget ID for a specific widget based on the widget label.
             *
             */
            public function getWidgetId(widgetLabel:String, isController:Boolean = false):Number
            {
                var id:Number = Number.NaN;
                if (isController){
                    for (var c:Number = 0; c < configData.controls.length; c++)
                    {
                        if (configData.controls.label == widgetLabel)
                        {
                            id = configData.controls.id;
                        }
                    }
                }else{
                    for (var w:Number = 0; w < configData.widgets.length; w++)
                    {
                        if (configData.widgets.label == widgetLabel)
                        {
                            id = configData.widgets.id;
                        }
                    }
                }
                return id;
            }


and use this code:

ViewerContainer.getInstance().widgetManager.getWidgetId("hc",true)


The new second optional parameter tells the function you are looking for a UI Widget (controller).
0 Kudos
Drew
by
Occasional Contributor III
Thanks for the code Robert.
It works to get the widget ID, but when i try and find the widget i hit and error.

Error
public function getWidget(widgetId:Number, openWidgetIfNot:Boolean = false):IBaseWidget
.
.
.
if (idx == null)
{
   throw new ArgumentError("Invalid widgetId: " + widgetId);
}
.
.
.


My widget id comes back as ID = 1007
my code
var wid:Number =  ViewerContainer.getInstance().widgetManager.getWidgetId("MyWidgetLabel",true);
var widget:IBaseWidget =  ViewerContainer.getInstance().widgetManager.getWidget(wid);


I might end up making my own public collection to hold these widgets in so I can find them.

Drew
0 Kudos
Drew
by
Occasional Contributor III
Here is my solution...

In the widgetManager.mxml file i had to make the variable "controlContainer" public and added my own function...

                        //=====================================================================    // Get UI Widget by Label.....,. (Make controlContainer PUBLIC)    //=====================================================================    public function getUIWidget(widgetLabel:String):IBaseWidget    {     for (var x:Number = 0; x < controlContainer.numElements; x++)     {      var widget:IBaseWidget = controlContainer.getElementAt(x) as IBaseWidget;      if (widget.widgetTitle.toUpperCase() == widgetLabel.toUpperCase())       return widget;     }          return null;    }


Drew
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Drew,

   Glad you got that working. Don't forget to mark YOUR post as the answer then.
0 Kudos
Drew
by
Occasional Contributor III
Thanks for your help Rob. It guided me into the right direction.

Post marked!

Drew
0 Kudos