0 Replies Latest reply on Oct 12, 2012 2:52 AM by mon_zy

    Flex Automation: submenu cannot be recognized when automating custom menu

    mon_zy

      I have scrollable menu class which extends flex menu. user can specify the menu height. when there are too many menu item, a vertical scrollbar will show.

       

      here is the main method in my ScrollableMenu.as:

       

      public static function createMenu(parent:DisplayObjectContainer, mdp:Object, showRoot:Boolean=true):ScrollableMenu

              {

                  var menu:ScrollableMenu = new ScrollableMenu();

                  menu.tabEnabled = false;

                  menu.owner = DisplayObjectContainer(FlexGlobals.topLevelApplication);

                  menu.showRoot = showRoot;

                  menu.isMainMenu = true;

                  popUpMenu(menu, parent, mdp);

                  return menu;

              }

       

      override mx_internal function openSubMenu(row:IListItemRenderer):void

              {

                  supposedToLoseFocus = true;

                 

                  var r:Menu = getRootMenu();

                  var menu:ScrollableMenu;

                 

                  // check to see if the menu exists, if not create it

                  if (!IMenuItemRenderer(row).menu)

                  {  trace("no menu")

                      menu = new ScrollableMenu();

                      menu.maxHeight = this.maxHeight;

         

                      menu.parentMenu = this;

                      menu.owner = this;

                      menu.showRoot = showRoot;

                      menu.dataDescriptor = r.dataDescriptor;

                      menu.styleName = r;

                      menu.labelField = r.labelField;

                      menu.labelFunction = r.labelFunction;

                      menu.iconField = r.iconField;

                      menu.iconFunction = r.iconFunction;

                      menu.itemRenderer = r.itemRenderer;

                      menu.rowHeight = r.rowHeight;

                      menu.scaleY = r.scaleY;

                      menu.scaleX = r.scaleX;

                     

                      // if there's data and it has children then add the items

                      if (row.data &&

                          _dataDescriptor.isBranch(row.data) &&

                          _dataDescriptor.hasChildren(row.data))

                      {

                          menu.dataProvider = _dataDescriptor.getChildren(row.data);

                      }

                      menu.sourceMenuBar = sourceMenuBar;

                      menu.sourceMenuBarItem = sourceMenuBarItem;

                     

                      IMenuItemRenderer(row).menu = menu;

                      PopUpManager.addPopUp(menu, r, false);

                  }

                 

                  subMenu = IMenuItemRenderer(row).menu as ScrollableMenu;

                 

                  super.openSubMenu(row);

                 

                  //adjust the submenu position if scrollbar exists

                  if(verticalScrollBar) {

                      var menu_x:Number = IMenuItemRenderer(row).menu.x + verticalScrollBar.width;

                      var menu_y:Number = IMenuItemRenderer(row).menu.y ;

                      IMenuItemRenderer(row).menu.move(menu_x,menu_y);

                  }

                 

              }

       

      //--------------------------------------------------------------end----------------------- -------------------------------------------------------------------//

       

      I created a delegate for the scrollablemenu, and I added xml definition in RFT's flexEnv.xml(I basically copy the def for menu and added scroll event)

       

      public class TestScrollableMenuDelegate extends MenuAutomationImpl

          {

       

              public static function init(root:DisplayObject):void

              {

                  Automation.registerDelegateClass(ScrollableMenu, TestScrollableMenuDelegate);

              }

             

              public function TestScrollableMenuDelegate(obj:ScrollableMenu){

                  super(obj);

              }

       

          }

       

      Now, everything is working(scroll, select main menu item) except the action on submenu cannot be recorded.

      I do not know what I  should add to my delegate class to make it work.

      Hope someone can give a hint!