removeTitlebarButton ? (addTitlebarButton)

380
2
05-02-2012 05:11 AM
JanPacak
New Contributor
Hello,

i have a one question. Exists a function as removeTitlebarButton? I need remove a icon from header of widget after action (e.g. after click on button) I know addTitlebarButton but I can't find a remove function. Can anybody help me?

Thanks
Tags (2)
0 Kudos
2 Replies
IvanBespalov
Occasional Contributor III
I can't find a remove function too,
but
ESRI Viewer is extandable application

you can extend WidgetTemplate.as as you want (this code is just a sample - not tested)
// Viewer version is 2.5
    public function addTitlebarButton(btnIcon:String, btnTip:String, btnFunction:Function, selectable:Boolean = true):void
    {
        var btn:TitlebarButton = new TitlebarButton();
        btn.callback = btnFunction;
        btn.selectable = selectable;
        btn.source = btnIcon;
        btn.toolTip = btnTip;

        if (selectable)
        {
            btn.addEventListener(MouseEvent.CLICK, titlebarButton_clickHandler);
            if (headerToolGroup.numElements == 0)
            {
                selectedTitlebarButtonIndex = 0; // automatically select the first button added
            }
        }

        headerToolGroup.addElement(btn);
    }
 
 public function removeTitlebarButton(item:TitlebarButton):Boolean
 {
  var success:Boolean = false;
  
  // next logic is the same as in headerToolGroup.removeElement(...)
  if (item != null)
  {
   try
   {
    var buttonIndex:int = headerToolGroup.getElementIndex(item);
    if (buttonIndex > -1)
    {
     headerToolGroup.removeElementAt(buttonIndex);
     success = true;
    }
   }
   catch (error:ArgumentError) // child element not exists in headerToolGroup
   {
    trace(error.getStackTrace());
   }
   
  }
  
  return success;
 }
0 Kudos
JanPacak
New Contributor
Many thanks Ivan. Your idea help me and it fixed my problem.
0 Kudos