7 Replies Latest reply on Sep 17, 2014 8:46 AM by carrzkiss

    if else statement when button click

    carrzkiss Level 1

      Hello All;

      I have run into a project, that I am having an issue on how to code.

      Scenario.

       

      You have 3 states of a button.

      MouseOver

      MouseOut

      MouseClick

       

      Now.

      When the Mouse Click is done, I need to do the following.

      Under the MouseOver and MouseOut.

       

      IF MouseClick THEN

      (Check to see if the Button was clicked or not)

      Keep state of button

      ELSE

      (If button was not clicked, then change its state)

      Change State of Button

       

      How would I code this?

      Thank You

      Wayne

        • 1. Re: if else statement when button click
          joel_pau Level 5

          Hello,

           

          You have 2 jQuery functions to do that: .addClass() and .hasClass()

           

          1) click event:

          sym.$(e.target).addClass("clicked");

           

          2) mouseover and mouseout events:

          if ( sym.$(e.target).hasClass("clicked") ) { doSomething } else { doAnotherthing };

          • 2. Re: if else statement when button click
            carrzkiss Level 1

            Love it.
            Thank you so much, this is going to come in so handy.
            I love the coding aspects of projects, not just allowing the program to do all the work.
            Have an awesome day Joel.
            Wayne

            • 3. Re: if else statement when button click
              carrzkiss Level 1

              Have a slight issue, that I just noticed. (To excited, that I jumped the gun).
              I have 2 buttons.
              When I click on button1, it sets its state to CLICKED.
              Now, if I click the other button2, I have the code to change the other button1 to its NON-Clicked state.
              However, when I MouseOver the previous clicked button1, it changes to the CLICKED state (Color).

               

              Anyway to make it so that it will recognize that another button is currently set as CLICKED, and not change on mouseover to the click state color?

               

              Hope this makes since. (basically, just do not want the non-current clicked button to change to clicked state, when it is not currently clicked on.)

              • 4. Re: if else statement when button click
                carrzkiss Level 1

                A better explination.

                 

                Once another button is clicked, it needs to EXPIRE the previously clicked buttons.
                So, each button would be like so. (I would think)

                 

                Button1
                sym.$(e.target).addClass("clicked1");

                 

                Button2

                sym.$(e.target).addClass("clicked2");

                With each button having its on ClassName, should make it easier to Expire/Disable it, once another button is clicked.
                Just not to sure where to do it at.

                • 5. Re: if else statement when button click
                  joel_pau Level 5

                  Here is an idea with some explanations: button Class.zip - Box

                  I use the same class to target each button.

                  • 6. Re: Re: if else statement when button click
                    joel_pau Level 5

                    Productivity update: i added a second file (same link: see previous post).

                    Productivity means i set then use a symbol.

                    • set ==> right click then convert to symbol.
                    • use ==> drag and drop from library to stage.
                    • 7. Re: if else statement when button click
                      carrzkiss Level 1

                      The first one is simpler, however, in the case that I am faced with, I think that the symbols is going to be the way to go.
                      Reason: I am using Images for each of the animations. Though it worked great with the first Class, I will not be able to change the images, as each button has its own images.
                      So, the Symbols will be the way I will take this one.
                      You Rock, and thank you so much for your time on this one.
                      This is going to be for a lesson that I was asked to do, to go along with a previous lesson on Image Rollover in EA, and I would like to give you credit for your hard work.
                      If you have a website, I would love to send people your way.

                       

                      Take care and have a Rockin' rest of the week.
                      Wayne