1 Reply Latest reply on May 3, 2011 2:32 AM by kishor papnai

    Will only work with component button

    sus3135 Level 1
      There is probably a simple answer to this, but I'm not seeing it. Got a drop down menu - Flash 8 - AS2. The problem is that it works like a charm if the MainMenu_btn is a Component - but if I make my own button it doesn't work.

       

      Menu is created with this code.  Button is created in Flash - "Insert - New Symbol - Button.

       

      Can anyone tell me why?
      ---

       

      _global.style.setStyle("themeColor", "haloGray");
      import mx.controls.Menu;
      MainMenu_btn.useHandCursor = true;
      var cmMainMenu:Menu = Menu.createMenu();
      cmMainMenu.addMenuItem({label: "Welcome", instanceName:"miIWelcome"});
      cmMainMenu.addMenuItem({label: "Introduction", instanceName:"miNavigation"});
      cmMainMenu.addMenuItem({label: "Exit", instanceName: "Exit"})

       

      // Add a change-listener to Menu to detect which menu item is selected
      var changeListener = new Object();
      changeListener.change = function(evt_obj:Object) {

       

      // Code for when the user makes a specific selection
      var item_obj:Object = evt_obj.menuItem;
      if( item_obj.attributes.label=="Welcome" ){
      loadMovie("data/exported0.swf","emptyClip");
      }
      else if (item_obj.attributes.label == "Introduction") {
      loadMovie("Introduction.swf","emptyClip");
      }
      }

       

      cmMainMenu.addEventListener("change", changeListener);

       


      //Add a button that displays the menu when the button is clicked
      var listener = new Object();
      listener.click = function(evtObj) {
      var button = evtObj.target;
      //get reference to the button
      // Display the menu at the bottom of the button
      _root.cmMainMenu.show(button.x, button.y+button.height);
      }
      MainMenu_btn.addEventListener("click", listener);
      stop();

       


        • 1. Re: Will only work with component button
          kishor papnai

          for customized button you will have to write code like this.

           

          writting event is the difference here in component and customized button.

           

           

          _global.style.setStyle("themeColor","haloGray");
          import mx.controls.Menu;
          MainMenu_btn.useHandCursor = true;
          var cmMainMenu:Menu = Menu.createMenu();
          cmMainMenu.addMenuItem({label:"Welcome", instanceName:"miIWelcome"});
          cmMainMenu.addMenuItem({label:"Introduction", instanceName:"miNavigation"});
          cmMainMenu.addMenuItem({label:"Exit", instanceName:"Exit"});
          // Add a change-listener to Menu to detect which menu item is selected
          var changeListener = new Object();
          changeListener.change = function(evt_obj:Object) {
              // Code for when the user makes a specific selection
              var item_obj:Object = evt_obj.menuItem;
              if (item_obj.attributes.label == "Welcome") {
                  loadMovie("data/exported0.swf", "emptyClip");
              } else if (item_obj.attributes.label == "Introduction") {
                  loadMovie("Introduction.swf", "emptyClip");
              }
          };
          cmMainMenu.addEventListener("change",changeListener);

           

          MainMenu_btn.onRelease = function(e) {
              var button = MainMenu_btn;
              _root.cmMainMenu.show(button._x,button._y+button._height);
          };
          stop();