8 Replies Latest reply on Jun 7, 2007 6:04 AM by Bayani Portier

    Flushing the Mouse click stack

    Bayani Portier Level 1
      Hi Guys,

      I'm currently working on a pretty huge project with an annoyingly high level of QA. We have a section where the user must answer yes/no to a whole stack of questions. Sounds easy, but here's the catch.

      Incidently, the program has to do with psychometric testing, not surveys, so all of you may breathe easy.

      We're currently using a Cairngorm architecture, so everything is absolutely AS based, and we've made our own custom button called AnswerComponent. So here's the problem.

      When a user is using a slower pc, and they mash the left mouse button over an answer, the questionnaire will advance a series of questions, as the buttons are in exactly the same position. What would be really neat, clean and handy, is if I could somehow flush out the mouse click stack, so that the page doesn't automatically advance.

      Any other workarounds would be awesome, but I thought I would list what we have done already:
      1. Placed a timer on an arm/disarm function so that the user can't click on a button quicker than once a second -
      Fixes the problem on faster computers, as the event stack flushes faster than the user can click, however only kind of fixes the problem on slower PC's, as the events don't get flushed fast enough for our intrepid trigger happy friends.

      2. Placed a transparent panel between switched screens with a listener that resets a timer every time it receives a click.
      Fixes the problem, BUT, QA assures me that this screws up the test, as the user receives delays between questions.

      3. Tried the stopImmediatePropagation() event after the user has clicked the button, but this seems to disable all buttons.

      Really stuck here, and I could use some help. First person to come up with a clue to solve it gets my "Awesome Flex Programmer of Doom" award. :P



        • 1. Re: Flushing the Mouse click stack
          buabco Level 1
          Any, just as an idea, but shouldn't the button remain disabled until the user answer a question on the page?
          • 2. Re: Flushing the Mouse click stack
            Bayani Portier Level 1
            Hi Buabco,

            Thanks for responding. I discovered exactly why the button is stacking clicks. The same mxml file is being used, and the button is hardwired into it.

            This is a requirement, as eventually, this will be a dynamic system. Unfortunately, for our current maintenance release, we can't refactor code to fix the root problem, so I've had to think about a workaround.

            About the best I've come up with, I can only really explain as an analogy, as the code is far too spread out to post here. If anyone comes up with a better solution, please let me know.

            Picture a mouse click as a tennis ball. (The MouseEvent.MOUSEUP specifically)
            Picture the listener as a big switch plate.

            Currently, the same plate is being used, and if it is pummeled by hundreds of tennis balls from a tennis ball launcher, hundreds of clicks are being registered, but only one at a time in rapid progression.

            Now imagine that there is a giant piece of perspex shielding sitting in front of the button, that's raised normally. Thus the button is armed.

            When the first tennis ball hits, the giant perspex shield drops down and blocks any subsequent tennis balls that hit it.

            There is a timer event that is launched when the shield goes down. When the timer runs out, the button can be clicked again.

            This is essentially what I originally tried, and it failed on the other exercises.

            What I came up with today in a caffeine induced rage was to shorten the timer so that it wouldn't affect the user's experience, BUT, if multiple clicks were being registered, the timer gets reset.

            So basically when the shield is down, the clock starts ticking, but if a tennis ball hits it, the clock starts all over again.

            If anyone has a better idea than this bubble gum and sticky tape method, I'm all ears.

            • 3. Flushing the Mouse click stack
              I have a totally random guess that I haven't tried out and quite likely doesn't work at all, but...

              Could you in your event listener remove the event listener from the button? And only when the new question is loaded re-assign the event listener? That way it would only ever pick up the first click on the button for any single question.

              N.B. This is basically what buabco suggested.
              • 4. Flushing the Mouse click stack
                Possibly the same thing again:

                - Disable the button on the click event (button.enabled=false)...
                - Load the new question...
                - Enable the button on the end of the load question event / process...

                That should remove any extra things, timers, transaprent thingys, and shouldn't collect any clicks that you don't want.

                Hope that helps.
                • 5. Re: Flushing the Mouse click stack
                  Bayani Portier Level 1
                  Hi Oddsy,

                  Thanks for the suggestion, but I've already tried that with no success.
                  • 6. Re: Flushing the Mouse click stack
                    Bayani Portier Level 1
                    Hi QuickStick,

                    I'll try that and keep you posted as to success.
                    • 7. Re: Flushing the Mouse click stack
                      HyderAlamgir Level 1
                      Using a timer isn't really the most efficient way.

                      x:int =0;
                      onButtonClick () {

                      if (x==0) {
                      load the next page

                      when next page loads, x=0;

                      Since x is assigned to 0 only when the next page completes loading, the if condition will not let you move the next page.

                      that should shield the plate!

                      • 8. Re: Flushing the Mouse click stack
                        Bayani Portier Level 1
                        Hi Hyder,

                        normally I would agree with you that a timer isn't the best way, but the problem is that we actually did implement something similar, but instead of using an int, we used a boolean.

                        Unfortunately, it seems as though when a system is executing, the page mutators occur about the same time that the next mouse event hits, so all that happens is the following race condition:

                        Cycle | Mouse Event | Page | Boolean
                        1 | Click | 1 | False -> True
                        2 | Click | 2 | False -> True
                        3 | Click | 3 | False -> True

                        well, you get the idea.

                        Good thinking, but it's still oldschool, rather than Cairngorm/Flex