0 Replies Latest reply on Aug 2, 2007 8:17 AM by cws14

    Setting a PopUpMenuButton in actionscript

    cws14 Level 1
      Hiya,

      I just might be idiotic, but it took me forever to figure out how to set a PopUpMenuButton via actionscript, so I thought I might share my solution with you all in case anyone has the same problem. The gist of what I was trying to do was, I had a list of charts in a PopUpMenuButton on a screen (within a viewstack), and when I entered that screen I needed to set the PopUpMenuButton to display the correct type of chart (icon and label). Anyways, you can't do it directly through the button, you need to access the button's popup attribute and then set the selectedIndex of that attribute - which seems a little roundabout to me, but it works I guess.

      So here goes with the example:

      var menuitems:ArrayCollection = new ArrayCollection([
      {label: "Bar", icon: bar},
      {label: "Pie", icon: pie},
      {label: "Area", icon: area}])

      <mx:PopUpMenuButton id="chartTypeButton" dataProvider="{menuitems}" labelField="label" showRoot="false"/>

      function setChartTypeButton(chartTypeIndex:Number):void {
      var menu:Menu = chartTypeButton.popUp as Menu;
      menu.selectedIndex = chartTypeIndex;
      }

      So there you go. It's not really a complete example, but hopefully it helps!

      Cheers,
      Chloe