6 Replies Latest reply on Nov 16, 2009 8:17 AM by Rhida

    Disable 2 clicks (doubleclick)

    Rhida

      Hi,

       

      I've got this little program here. I have several buttons wich loads movies into a movieclip. When you hit once, it takes 1,5 seconds when the flashy makeup is final and the content is visible.

       

      When i hit a button 2-times the website turns into a epilepsic repeated load.

       

      Thats not funny   Check the code:

      /* a node in the tree has been selected */
      treeListener.change = function (evt:Object) {
       var node = evt.target.selectedItem;
       var is_open = evt.target.getIsOpen (node);
       var is_branch = evt.target.getIsBranch (node);
       var node_to_close = node.getBrotherChilds (this.target);
       // close the opened node first
       if (this.target.getIsOpen (node_to_close) and this.target.getIsBranch (node_to_close)) {
        this.target.setIsOpen (node_to_close, false, true, true);
        this.open_next = node;
          // main_node
        
        gotoAndPlay(""+ node.attributes.action);
        //loadMovie(""+ node.attributes.action, "mc_holder");
         
           } else {
        if (is_branch) {
         this.target.setIsOpen (node, true, true, true);
         
         gotoAndPlay(""+ node.attributes.action); 
        
        } else {
         this.target.selectedNode = node;
         //childnode
         gotoAndPlay(""+ node.attributes.action);
        }
        this.open_next = undefined;
       }
      };
      treeListener.closeNode = function (node:XMLNode) {
       for (var a in node.childNodes) {
        if (this.target.getIsOpen (node.childNodes[a])) {
         this.closeNode (node.childNodes[a]);
        }
       }
       this.target.setIsOpen (node, false, false);
      };
      

       

      So, I want to freeze my animation totally during processing, so that:

       

      1: click
      2: processing, takes 1.5 second (button is disabled)
      3, after 1.5 second: finished (button is enabled)

       

       

      I know that you can fix this with   setTimeout(), can anyone help me?

      Thanks in advance!

        • 1. Re: Disable 2 clicks (doubleclick)
          Adamcbrz Level 2

          Why don't you just set it's enabled property to false and then turn it back on once you are ready.

           

          my_mc.enabled = false; //turns click events off for a movieclip or button

           

          my_mc.enabled = true; //turn it back on.

          1 person found this helpful
          • 2. Re: Disable 2 clicks (doubleclick)
            Rhida Level 1

            Hi thanks for your post, but how do I program that?

             

            I think something like: when a item is clicked { disable all buttons/items in the menu, wait 5 seconds, enable all buttons/items}

             

            But in the code..?

             

            thanks

            • 3. Re: Disable 2 clicks (doubleclick)
              Ned Murphy Adobe Community Professional & MVP

              I don't see any button code you mention in what you show, but the solution that was offered to you is the code to use.  If your button that starts this process has an nstance name of "btn", then in that button's onRelease function you would set the button to be disabled using...

               

              btn.enabled = false;

               

              And whatever code would mark the end of the processing that takes 1.5 seconds, you would have...

               

              btn.enabled = true;

               

              If there are multiple buttons, then you do it for all of them at once, telling each to be disabled/enabled in your code.

              • 4. Re: Disable 2 clicks (doubleclick)
                Rhida Level 1

                Check the startpost there is the code available.

                The menu is generated by elements from an xml file.

                 

                 if (this.target.getIsOpen (node_to_close) and this.target.getIsBranch (node_to_close)) {
                  this.target.setIsOpen (node_to_close, false, true, true);
                  this.open_next = node;
                    // main_node
                 
                  gotoAndPlay(""+ node.attributes.action);
                  //loadMovie(""+ node.attributes.action, "mc_holder");
                  
                     } else {
                  if (is_branch) {
                   this.target.setIsOpen (node, true, true, true);
                  
                   gotoAndPlay(""+ node.attributes.action);
                 
                  } else {
                   this.target.selectedNode = node;
                   //childnode
                   gotoAndPlay(""+ node.attributes.action);
                  }
                  this.open_next = undefined;
                }
                };
                treeListener.closeNode = function (node:XMLNode) {
                for (var a in node.childNodes) {
                  if (this.target.getIsOpen (node.childNodes[a])) {
                   this.closeNode (node.childNodes[a]);
                  }
                }
                this.target.setIsOpen (node, false, false);
                };

                 

                Has someone a code example or a hint I can use? thanks!!

                • 5. Re: Disable 2 clicks (doubleclick)
                  Ned Murphy Adobe Community Professional & MVP

                  You already received two examples of code to use, but you apparently do not know how to use it.  How much experience do you have with using Flash/actionscript?  Did you create the code that you are showing?  I get the impression you didn't because you would know what code is relevant to a button being interacted with if you did, though I could be wrong.  If I am missing the code that is assigned to the buttons in anything you have shown so far, please highlight it in some way to make it obvious.

                  • 6. Re: Disable 2 clicks (doubleclick)
                    Rhida Level 1

                    Hi Ned,

                     


                    I programmed a long time ago based on a existing code.

                    I jumped into my flash bible and google and found what I needed. I used removeEventListener and placed it back when setTimout(); is completed.

                     


                    this is the solution:

                     

                    treeListener.change = function (evt:Object) {
                         
                    tree.removeEventListener('change', treeListener);
                    setTimeout(enableF,2500);
                    
                         
                         var node = evt.target.selectedItem;
                         var is_open = evt.target.getIsOpen (node);
                         var is_branch = evt.target.getIsBranch (node);
                         var node_to_close = node.getBrotherChilds (this.target);
                         // close the opened node first
                         if (this.target.getIsOpen (node_to_close) and this.target.getIsBranch (node_to_close)) {
                              this.target.setIsOpen (node_to_close, false, true, true);
                              this.open_next = node;
                              // main_node
                              gotoAndPlay(""+ node.attributes.action);
                              //loadMovie(""+ node.attributes.action, "mc_holder");
                         
                                     } else {
                              if (is_branch) {
                                   this.target.setIsOpen (node, true, true, true);
                                   gotoAndPlay(""+ node.attributes.action);
                              } else {
                                   this.target.selectedNode = node;
                                   //childnode
                                   gotoAndPlay(""+ node.attributes.action);
                              }
                              this.open_next = undefined;
                         }
                    function enableF(){
                    tree.addEventListener('change', treeListener);
                    }
                    };
                    

                     

                    Thanks folks