0 Replies Latest reply on Jun 10, 2009 3:38 PM by Applied CD

    Best practices for adding CLICK listeners to complicated menus?

    Applied CD Level 1

      OK, I’m gonna wear out my welcome but here’s my last question of the day:

       

      I’ve got a project that is essentially a large collection of menus, some buttons common across multiple screens, others unique. The following link is the work in progress, most of the complexity is in the “Star Action Items and Forms” area (btw: the audio in the launch presentation is just a placeholder track, I know we can't use it):

       

      http://www.appliedcd.com/Be-A-star/Be-A-star.html

       

      To deal with the large number buttons my timeline simply has the following for every menu frame:

       

      stop();
      initFrame();

       

      The initFrame() function then has a list of frames and activates the buttons appearing on each screen, a very simplified example follows. In this example commonButtons span all 3 menus, semiCommonButtons span menu 2 and 3, button1A, button2A, etc… are unique per menu.:

       

      //----------------------------------------------
      function initFrame():void {
           var myFrame:String = this.currentLabel;
           commonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
           commonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
           commonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);
           switch(myFrame) {
                case "menu1":
                     button1A.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button1B.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button1C.addEventListener(MouseEvent.CLICK,onInternalLink);
                break;
                case "menu2":
                     semiCommonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
                     semiCommonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
                     semiCommonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);

       

                     button2A.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button2B.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button2C.addEventListener(MouseEvent.CLICK,onInternalLink);
                break;
                case "menu3":
                     button3A.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button3B.addEventListener(MouseEvent.CLICK,onInternalLink);
                     button3C.addEventListener(MouseEvent.CLICK,onInternalLink);
                break;
           };
      }

       

      The way the project was designed, I “thought” menu3 would only be accessible through menu2, thus guaranteeing that the semiCommonButtons would get initialized, but I forgot the functionality of my back button could jump the user directly from menu1 to menu3. The solution is simple, initialize every button on every navigation  target, however, is this really the best way to initialize a bunch of buttons? Another possible approach would be to have an array of button instance names and a function that said: if instance XYZ exists, add listener, then simply loop through the array on every nav target. Anyone with more experience have advice on best practices in this situation?