7 Replies Latest reply on Aug 11, 2006 6:33 AM by $era

    Active Button States

    KrisCons
      Hi All,

      I am trying to achieve creating active button states in flash within my movieclip. My guess is it needs to be more technical than what I am attempting so if someone can point me in the right direction or even provide a snippet of code that will help, I would appreciate it.

      What I have so far:

      I have 3 button movieclips on stage each with the their own instance names (button1, button2 and button3). They have 3 keyframes, "up", "over" and "active".

      The code for button1 is as follows (and the others are similar as you can guess):

      on(rollOver) {
      _root.button1.gotoAndStop(2); // over state
      }

      on(rollOut) {
      _root.button1.gotoAndStop(1); // up state
      }

      on(release) {
      _root.button1.gotoAndStop(3); // active state
      _root.button2.gotoAndStop(1); // set this to up state
      _root.button3.gotoAndStop(1); // set this to up state
      }

      Obviously this works until I move my mouse away from over the top of the button I have pressed becauseof the on(RollOut) event.

      Any suggestions on how I can get this to remain as the Active state until i click another button please?

      Regards
      K

        • 1. Re: Active Button States
          Darshan Rane Level 3
          hi

          i rollout state

          on(rollOut) {
          if(flag1 == false) //flag3 : boolean var
          {
          _root.button1.gotoAndStop(1); // up state
          }
          else
          {
          _root.button1.gotoAndStop(3);
          }
          }


          and in release

          on(release) {
          _root.button1.gotoAndStop(3); // active state
          flag1 == true;
          _root.button2.gotoAndStop(1); // set this to up state
          flag2 = false;
          _root.button3.gotoAndStop(1); // set this to up state
          flag3 = false;
          }

          remember to do this for every button

          hope it works

          its only to check if button is clicked or not
          • 2. Re: Active Button States
            KrisCons Level 1
            Hi

            Not a actionscript guru so could you please indicate how and where i declare the flag variable? Is it on each button instance or just on a Actions layer keyframe?

            What would the syntax be?
            Thanks
            • 3. Re: Active Button States
              KrisCons Level 1
              Hi
              I amended the code to the following: (only testing one button here)


              on(rollOver) {
              if(isactive == true) {
              _root.button1.gotoAndStop(3); //active state already on
              } else {
              _root.button1.gotoAndStop(2); //over state
              }
              }

              on(rollOut) {
              if(isactive == true) {
              _root.button1.gotoAndStop(3); // leave active
              } else {
              _root.button1.gotoAndStop(1); //over state
              }
              trace(isactive);
              }


              on(release) {
              _root.button1.gotoAndStop(3);
              isactive == true;
              }

              When the trace is run, the variable isactive is UNDEFINED. Why is this?
              Tahnks in advance
              • 4. Re: Active Button States
                Darshan Rane Level 3
                declare these var

                var isactive : Boolean
                isactive = false
                • 5. Re: Active Button States
                  Darshan Rane Level 3
                  delare it on separete actions layer
                  on a frame before your buttons frame comes

                  var isactive : Boolean
                  isactive = false

                  even i am a learner in AS not a guru
                  • 6. Re: Active Button States
                    KrisCons Level 1
                    Hi

                    I have done what you said but isactive is constantly undefined.

                    I have an actions layer with the following in keyframe 1:

                    var isactive:Boolean;
                    isactive == true;

                    And I have another layer containing my button_mc instance which has the following code:

                    on(rollOver) {
                    if(isactive == true) {
                    _root.button1.gotoAndStop(3); // active state already on
                    } else {
                    _root.button1.gotoAndStop(2); // mouse over state
                    }
                    }

                    on(rollOut) {
                    if(isactive == true) {
                    _root.button1.gotoAndStop(3); // leave active as it is
                    } else {
                    _root.button1.gotoAndStop(1); // up state
                    }
                    trace(isactive);
                    }


                    on(release) {
                    _root.button1.gotoAndStop(3); // active state
                    isactive == true; // set isactive var to true
                    }

                    If you can spot any problems then please point them out, otherwise I'll give up!

                    Cheers
                    • 7. Re: Active Button States
                      $era
                      Hi
                      i thing the promblem is mistyped in your code a very small but very commone.
                      when you want to assign a value to a variable you use single equal sign( = ),
                      but when you wanna check for equality between two values you use double equal sign ( == ).

                      i hope that will help you.

                      var isactive:Boolean;
                      isactive == true;


                      on(rollOver) {
                      if(isactive == true) {
                      _root.button1.gotoAndStop(3); // active state already on
                      } else {
                      _root.button1.gotoAndStop(2); // mouse over state
                      }
                      }

                      on(rollOut) {
                      if(isactive == true) {
                      _root.button1.gotoAndStop(3); // leave active as it is
                      } else {
                      _root.button1.gotoAndStop(1); // up state
                      }
                      trace(isactive);
                      }


                      on(release) {
                      _root.button1.gotoAndStop(3); // active state
                      isactive == true; // set isactive var to true
                      }