4 Replies Latest reply on Aug 5, 2013 6:46 AM by robboerman

    infinite button unbind/bind loop

    Sportingersen

      Hello everyone,

       

      I have two buttons. The click-event unbinds the click-event from the button which was clicked. when i click the other button, i rebind the events to the first button. This works one time only. When i bind the click event with a secound "loop" i can get it work 2 times, and so on. How can i make it easy and infinite ?

       

      here is my code:

       

      // click event button1

      sym.getSymbol("Produktionen").play("click");

      sym.$("Produktionen").unbind("mouseover");

      sym.$("Produktionen").unbind("mouseout");

      sym.$("Produktionen").unbind("click");

       

       

      // check for status of button2. If button2 had been clicked, all events have been unbound on button2. Then rebind of all events for button2

      if (sym.getSymbol("Personen").getPosition() > 5000) {

       

      // binding of the click event for button2. here comes my problem with the loop.

            sym.$("Personen").bind("click",function(){

            sym.getSymbol("Personen").play("click");

            sym.$("Personen").unbind("mouseover");

            sym.$("Personen").unbind("mouseout");

            sym.$("Personen").unbind("click");

       

      // mouseover bind for button2

            sym.$("Personen").bind("mouseover",function(){

            sym.getSymbol("Personen").play("over");

            });

       

      // mousout bind for button2

            sym.$("Personen").bind("mouseout",function(){

            sym.getSymbol("Personen").play("out");

            });

       

      // mousout animation is triggert for button2.

           sym.getSymbol("Personen").play("out")

       

      }

       

      hope someone understands my problem

        • 1. Re: infinite button unbind/bind loop
          robboerman Level 4

          i don't 100% understand your problem, maby if you show the project, more people will respond.

          if its the loop what is causing the problem.

          add this code to the end of the function

          return false;

           

          it prevents the looping

           

          - Rob

          • 2. Re: infinite button unbind/bind loop
            Sportingersen Level 1

            Ok, i have created a test projekt to show my problem:

             

            link to the projekt

            link to projekt files

             

            After two clicks on the buttons they are stuck in the click event without any events bind to them. The more loops i use, more often i can click on the buttons.

            In my real projekt i have up to 12 buttons. I use a workaround with pictures of the clicked button which are moving on top of the still aktive,clicked button to prevent all mouseevents. I feel silly doing it like this

             

            i realy hope someone can help me.

            • 3. Re: infinite button unbind/bind loop
              Sportingersen Level 1

              I think there would be a way to prevent it. I tryed to get the code for the status check of the buttons and the rebind of events to work in the stage. It must be somehow independent from the click events on the button. I tried this

               

              compositionready:

               

              if (sym.getSymbol("button1").getPosition() > 3750) {

                    if (sym.getSymbol("button2").getPosition() > 3750) {

                   

                    sym.getSymbol("button2").play("out");

               

                    sym.$("button2").bind("mouseover",function(){

                    sym.getSymbol("button2").play("over");

                    });

               

                    sym.$("button2").bind("mouseout",function(){

                    sym.getSymbol("button2").play("out");

                    });

               

                    sym.$("button2").bind("click",function(){

                    sym.getSymbol("button2").play("click");

                    sym.$("button2").unbind("mouseover");

                      sym.$("button2").unbind("mouseout");

                      sym.$("button2").unbind("click");

                    });

                  }

                 

              if (sym.getSymbol("button2").getPosition() > 3750) {

                    if (sym.getSymbol("button1").getPosition() > 3750) {

                   

                    sym.getSymbol("button1").play("out");

               

                    sym.$("button1").bind("mouseover",function(){

                    sym.getSymbol("button1").play("over");

                    });

               

                    sym.$("button1").bind("mouseout",function(){

                    sym.getSymbol("button1").play("out");

                    });

               

                    sym.$("button1").bind("click",function(){

                    sym.getSymbol("button1").play("click");

                    sym.$("button1").unbind("mouseover");

                    sym.$("button1").unbind("mouseout");

                    sym.$("button1").unbind("click");

                    });

                  }

               

              but it doesnt work out. i dont know if i can nest If functions like this and i dont know if its ok to code it in the compositionready

              • 4. Re: infinite button unbind/bind loop
                robboerman Level 4

                the last one probably doesnt work because missing brackets.

                 

                but try to clean up your code by using variables and maby use the .each function to let the function be infinite.

                code it a bit to messy now to read for other people that haven't made the code

                1 person found this helpful