5 Replies Latest reply on Aug 11, 2006 10:46 AM by Rothrock

    Is there a better way to do this?

    Josh_Pratt Level 1
      I've got a menu I'm programing, but I am starting to forsee it being a lot of code.. Is there a way to cut down this code specifically? I've got it so that the alpha level of a button goes down to 60 onRollOver and the alpha goes back to 100 onRollOut. Is there a better way to do this? Here is my code:

      calendar.onRollOver = function() {
      calendar._alpha = 60;
      }
      calendar.onRollOut = function() {
      calendar._alpha = 100;
      }
      programs.onRollOver = function() {
      programs._alpha = 60;
      }
      programs.onRollOut = function() {
      programs._alpha = 100;
      }
      media.onRollOver = function() {
      media._alpha = 60;
      }
      media.onRollOut = function() {
      media._alpha = 100;
      }
      bios.onRollOver = function() {
      bios._alpha = 60;
      }
      bios.onRollOut = function() {
      bios._alpha = 100;
      }
      serving.onRollOver = function() {
      serving._alpha = 60;
      }
      serving.onRollOut = function() {
      serving._alpha = 100;
      }
        • 1. Re: Is there a better way to do this?
          Level 7

          "Josh Pratt" <webforumsuser@macromedia.com> wrote in message news:ebg860$npj$1@forums.macromedia.com...
          > I've got a menu I'm programing, but I am starting to forsee it being a lot of
          > code.. Is there a way to cut down this code specifically? I've got it so that
          > the alpha level of a button goes down to 60 onRollOver and the alpha goes back
          > to 100 onRollOut. Is there a better way to do this?

          If you want to assign button actions in a loop you can use numbered buttons like btn1, btn2 etc. or you can use an array of button
          names in the loop.
          Unless you are planning to make a lot more things happen with the buttons it doesn't seem worth all the trouble. If you just want
          to make some common rollover and rollout actions you can make a function that all buttons can use by sending their instance names to
          the function like this..

          // buttons
          //-----------------------------------
          calendar.onRollOver = function() {
          rollOverStuff(this);
          }
          //-----------------------------------
          calendar.onRollOut = function() {
          rollOutStuff(this);
          }
          //-----------------------------------

          // common functions
          //-----------------------------------
          function rollOverStuff(btn)
          {
          btn._alpha = 20;
          btn._y = 55; // button drops down a little
          }

          //-----------------------------------
          function rollOutStuff(btn)
          {
          btn._alpha = 100;
          btn._y = 50; // button back up
          }

          //-----------------------------------

          tralfaz


          • 2. Re: Is there a better way to do this?
            Rothrock Level 5
            The answer is yes. However you might want to give up your nice easy names and do something like this:

            for(var i=0;i<5;i++){
            this["myButton"+i].onRollover=function(){
            this._alpha=60;
            }
            this["myButton"+i].onRollOut=function(){
            this._alpha=100;
            }
            }

            In that case your buttons would need to be named myButton0, myButton1, and so on. You could even make this a bit snazzier by creating an array to hold the names of your buttons, the label that will show, different colors, etc. whatever you wanted. Then step through the array and apply the values. There are lots of ways to do this, experiment and play around.
            • 3. Re: Is there a better way to do this?
              Josh_Pratt Level 1
              Thanks for the reply. I'm just going to go ahead and assume that it works great. I won't be able to try it until work tommorow.

              Thanks again,

              Josh
              • 4. Re: Is there a better way to do this?
                Josh_Pratt Level 1
                Rothrock,

                I haven't really ever used arrays. How would I do what you are talking about with arrays?
                • 5. Re: Is there a better way to do this?
                  Rothrock Level 5
                  Just an idea to get you started down a road. I'm typing this up off the top of my head so there may be a typo or two. You might want to try it out on a brand new empty file before you try and jam it into your current project. Or just keep it as an idea for the next one.

                  I'm guessing you're making some kind of menu or such. Right?

                  Personally I don't use buttons so for this to work you will need to make a movie clip with whatever "button art you want" and a textfield called myLabel. Put that movieclip into the library and set its linkage to buttonArt.

                  First try it with only the three things in the array. Then try adding another and see how that works for ya!