10 Replies Latest reply on Jan 14, 2007 5:07 PM by Newsgroup_User

    multiple click

    guru_83
      hi, I need to make a button able to count several clicks. for exemple :
      1 click = action one
      2 clicks = action two
      3 clicks = action 3
      It also must be able to have an action after a long mousedown as a "repeat while the stilldown"

      Actually, my idea is to create a global, to force it to change every click and to watch the way it is and to launch the action after a timer. The problem is that the "repeat" slows down the program and the global doesn't change in the next frames :


      on exitFrame me
      go to the frame
      end

      on mousedown
      sprite(2).forecolor = random(5)
      global gtries
      gtries = gtries + 1
      startTimer
      repeat while the timer < 70
      if the timer > 70 then gtries = 0
      if the timer = 60 and gtries = 1 then put "1"
      if the timer = 60 and gtries = 2 then put "2"
      if the timer = 60 and gtries = 3 then put "3"
      if the timer = 60 and gtries = 4 then put "4"
      if the timer = 60 and gtries = 5 then put "5"
      if the timer = 60 and gtries = 6 then put "6"
      if the timer = 60 and gtries = 7 then put "7"
      if the timer = 60 and gtries = 8 then put "8"
      if gtries = 9 then
      set gtries = 0
      else
      if gtries > 8 then
      set gtries = 0
      end if
      updatestage
      end if
      end repeat
      end if
      end if
      end if
      end if
      end if
      end if
      end if
      end if
      end if
      end if
      end if

      end


      So, may be a counter of click woulb ok but I don't konw how to make it
        • 1. Re: multiple click
          Level 7
          Hi,

          You can detect if the mouse has been clicked twice by the doubleClick property.

          eg
          on mouseUp
          if the doubleClick = TRUE then
          -- do action 1
          else
          -- do action 2
          end if
          end

          You can't test for a triple click. I'm assuming the clicks have to be in close
          succession? So, you can use the above to separate a single and double click but
          I don't see how you could do this for the third because even if you had some way
          to record each click, how would the computer know teh user has finished
          clicking. For example, say you double clicked, would teh computer wait a second
          to see if there's a third click, or just immediately register that there's 2
          clicks so do action 2. I guess there's your answer, if you wnat multiple clicks,
          you'd need to record each in a variable like x = x +1, and then within a
          spcified time see what that variable value is to see how many clisks have been
          registered.

          I didn't follow your bottom code. But you don't need all the 'end if's below the
          'end repeat'.

          If you have an if-then condition of one line, like:
          if the timer = 60 and gtries = 1 then put "1"
          you don't need an 'end if'

          you only need an 'end if' when teh condition extends over mutiple lines like:
          if gtries = 9 then
          set gtries = 0
          end if

          As Mike would tell you, it's not a great idea to have repeat loops unnecessarily
          and avoid update as much as possible.

          Anyway, if you expalin the bottom bit in terms of what you want to achieve, I'm
          sure a better way of coding it could be suggested.

          regards
          Dean

          Director Lecturer / Consultant
          http://www.fbe.unsw.edu.au/learning/director
          http://www.multimediacreative.com.au


          • 2. Re: multiple click
            Level 7
            You should never use a repeat loop in a handler this way unless you
            absolutely don't care that anything else in the program stops functioning,
            which, by the way is sometimes desirable but not very often. Also, it's not
            a good idea to test for the timer = 60 because you might miss that moment.
            I think you probably wanted > 60

            Anyway, here's a tested way that I believe works the way you'd like without
            any interruption of interactivity or mouse events.

            A bit lengthy but it works.

            property pS, spriteNum, pMouseTimeStart, pMode, pClicks, pTimeOut,
            pLongMouseTimeOut, pElapsedTime

            on beginSprite me
            pS = sprite (spriteNum)
            pMouseTimeStart = 0
            pMode = #off
            pClicks = 0
            pTimeOut = 3000 -- duration in milliseconds to test for multiple clicks
            pLongMouseTimeOut = 5000
            pElapsedTime = 0
            end

            on mouseDown me
            if pMode = #off then
            pMouseTimeStart = the milliseconds
            pClicks = 1
            pMode = #on
            pElapsedTime = 0
            else
            pClicks = pClicks + 1
            end if
            end

            on exitFrame me
            if pMode = #on then
            pElapsedTime = the milliseconds - pMouseTimeStart
            if pElapsedTime > pTimeOut then
            case pClicks of
            1:
            put "1 click
            2:
            put "2 clicks"
            3:
            put "clicks"
            4:
            put "4 clicks"
            -- etc
            otherwise:

            end case
            if pElapsedTime > pLongMouseTimeOut then
            put "long mouse event happened"
            pMode = #off
            end if
            if the mouseDown = FALSE then
            pMode = #off
            end if
            else
            if pMode = #on then
            end if
            end if
            end if

            go to the frame

            end

            on mouseUp me
            if pElapsedTime > pTimeOut then
            pMode = #off
            end if
            end

            on mouseUpOutside me
            if pElapsedTime > pTimeOut then
            pMode = #off
            end if
            end


            --
            Craig Wollman
            Lingo Specialist
            Word of Mouth Productions
            212-928-9581

            www.wordofmouthpros.com
            "guru 83" <webforumsuser@macromedia.com> wrote in message
            news:eoa3j9$ec0$1@forums.macromedia.com...
            > hi, I need to make a button able to count several clicks. for exemple :
            > 1 click = action one
            > 2 clicks = action two
            > 3 clicks = action 3
            > It must be able to have an action after a long mousedown as a "repeat
            > while
            > the stilldown"
            >
            > Actually, my idea is to create a global, to see the way it is and to
            > launch
            > the action after a timer. The problem is that the "repeat" slows down the
            > program and the global doesn't change in the next frames :
            >
            >
            > on exitFrame me
            > go to the frame
            > end
            >
            > on mousedown
            > sprite(2).forecolor = random(5)
            > global gtries
            > gtries = gtries + 1
            > startTimer
            > repeat while the timer < 70
            > if the timer > 70 then gtries = 0
            > if the timer = 60 and gtries = 1 then put "1"
            > if the timer = 60 and gtries = 2 then put "2"
            > if the timer = 60 and gtries = 3 then put "3"
            > if the timer = 60 and gtries = 4 then put "4"
            > if the timer = 60 and gtries = 5 then put "5"
            > if the timer = 60 and gtries = 6 then put "6"
            > if the timer = 60 and gtries = 7 then put "7"
            > if the timer = 60 and gtries = 8 then put "8"
            > if gtries = 9 then
            > set gtries = 0
            > else
            > if gtries > 8 then
            > set gtries = 0
            > end if
            > updatestage
            > end if
            > end repeat
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            > end if
            >
            > end
            >


            • 3. Re: multiple click
              Level 7
              >I don't see how you could do this for the third because even if you had
              >some way
              > to record each click, how would the computer know teh user has finished
              > clicking.

              See my response...


              • 4. Re: multiple click
                Level 7
                soryr, Dean, you suggested that solution, but I didn't read far enough.



                --
                Craig Wollman
                Lingo Specialist
                Word of Mouth Productions
                212-928-9581

                www.wordofmouthpros.com
                "Dean Utian" <d.utian@unsw.edu.au> wrote in message
                news:45A8E6F6.55CA4D17@unsw.edu.au...
                > Hi,
                >
                > You can detect if the mouse has been clicked twice by the doubleClick
                > property.
                >
                > eg
                > on mouseUp
                > if the doubleClick = TRUE then
                > -- do action 1
                > else
                > -- do action 2
                > end if
                > end
                >
                > You can't test for a triple click. I'm assuming the clicks have to be in
                > close
                > succession? So, you can use the above to separate a single and double
                > click but
                > I don't see how you could do this for the third because even if you had
                > some way
                > to record each click, how would the computer know teh user has finished
                > clicking. For example, say you double clicked, would teh computer wait a
                > second
                > to see if there's a third click, or just immediately register that there's
                > 2
                > clicks so do action 2. I guess there's your answer, if you wnat multiple
                > clicks,
                > you'd need to record each in a variable like x = x +1, and then within a
                > spcified time see what that variable value is to see how many clisks have
                > been
                > registered.
                >
                > I didn't follow your bottom code. But you don't need all the 'end if's
                > below the
                > 'end repeat'.
                >
                > If you have an if-then condition of one line, like:
                > if the timer = 60 and gtries = 1 then put "1"
                > you don't need an 'end if'
                >
                > you only need an 'end if' when teh condition extends over mutiple lines
                > like:
                > if gtries = 9 then
                > set gtries = 0
                > end if
                >
                > As Mike would tell you, it's not a great idea to have repeat loops
                > unnecessarily
                > and avoid update as much as possible.
                >
                > Anyway, if you expalin the bottom bit in terms of what you want to
                > achieve, I'm
                > sure a better way of coding it could be suggested.
                >
                > regards
                > Dean
                >
                > Director Lecturer / Consultant
                > http://www.fbe.unsw.edu.au/learning/director
                > http://www.multimediacreative.com.au
                >
                >


                • 5. Re: multiple click
                  Level 7

                  "forum.macromedia.com" wrote:

                  > soryr, Dean, you suggested that solution, but I didn't read far enough.

                  Hi Craig,

                  No worries. As I was writing, I was thinking through the problem. So, intially
                  was thinking - how can you detect 3 clicks without monitoring the time for the
                  clicks to happen.

                  Anyway, you've given a more complete answer and said things I meant to cover a
                  bit more clearly. So, guru83, remember that:
                  * repeat loops should be used minimally because they can have wider implications
                  in a movie
                  * avoid using updateStage if possible, not a very CPU friendly bit of Lingo.
                  * not good to check 'the timer = 60' also because of the reliability of getting
                  to exactly 60 ticks. What Craig used in his behavior, 'the milliseconds' is
                  better than 'the timer''s measurement of ticks for accuracy and reliability.

                  I mentioned Mike because he told me off once when I gave a behavior to demo
                  something that had a script with a repeat loop and updatestage. Though, in that
                  demo, it was just doing one thing, so nothing else was happening in the movie
                  that could have been affected.

                  regards
                  Dean

                  Director Lecturer / Consultant
                  http://www.fbe.unsw.edu.au/learning/director
                  http://www.multimediacreative.com.au


                  • 6. Re: multiple click
                    Level 7

                    > I mentioned Mike because he told me off once when I gave a behavior to demo
                    > something that had a script with a repeat loop and updatestage. Though, in that
                    > demo, it was just doing one thing, so nothing else was happening in the movie
                    > that could have been affected.
                    >

                    Hehe. Yeah. There is a time and a place for everything, and the tight
                    repeat loop with updatestage in the middle has almost no time or place,
                    apart from incorrectness or laziness on the part of the developer (not
                    to say that I haven't been that lazy in the past...).

                    As someone has already mentioned, when you use a repeat loop like that,
                    all lingo stops processing until it is done. That will cause sounds and
                    video to skip, animations to be choppy or frozen, and a host of other
                    problems.

                    The 'workaround' to that is to stick updateStage() in the middle of it
                    which will kick off some of the lingo that is holding up, but it can
                    cause timing problems with things that require enterFrame vs exitFreame
                    and a host of other smaller (and much harder to troubleshoot) problems.

                    The good way to do it is to have an 'on enterFrame' script monitoring
                    the status of the request. The better way is to make a parent script
                    that can handle the whole thing in stepFrame.
                    • 7. Re: multiple click
                      Level 7
                      Continuing the dicussion on repeat loops and updatestage, I have a demo in my
                      Director pages to illustrate a few programming things and alos used it to illustrate
                      what not to do.

                      One example I have is a 'wait for a certain time' behavior below that creates a pause
                      for 2 second (2 sets of 60 ticks)
                      Frame behavior
                      on exitFrame me
                      wait 2*60
                      end
                      .
                      Movie script
                      -- Wait a certain amount of time
                      on wait numTicksToWait
                      startWait = the timer
                      repeat while (the timer - startWait) < numTicksToWait
                      updateStage
                      end repeat
                      end

                      It does much of what has just been said shouldn't be done. Here's a better of
                      achieving the same thing and converting it into a behavior where you can assign the
                      wait time as you attach it to a sprite:
                      -- define properties
                      property pNumMilliSecondsToWait, pStartWait

                      -- set the start time at the start
                      on beginSprite
                      pStartWait = the milliseconds
                      end

                      on exitFrame
                      wait pNumMilliSecondsToWait
                      end

                      -- wait custom handler
                      on wait pNumMilliSecondsToWait
                      -- loop in the frame until time is up
                      if (the milliseconds - pStartWait) < pNumMilliSecondsToWait then go the frame
                      end

                      on getPropertyDescriptionList
                      pList = [:] -- creates an empty property list
                      addProp pList #pNumMilliSecondsToWait, [#comment:"Number of milliseconds to wait:",
                      #format: #integer, #default:"1000"]
                      return pList
                      end

                      Besides the changes to milliseconds and restucturing the code, I'm now using:
                      if (the milliseconds - pStartWait) < pNumMilliSecondsToWait then go the frame
                      so instead of a repeat loop with updatestage, I'm just looping within the frame.

                      regards
                      Dean

                      Director Lecturer / Consultant
                      http://www.fbe.unsw.edu.au/learning/director
                      http://www.multimediacreative.com.au


                      • 8. Re: multiple click
                        Level 7

                        Jolly good piece of work there. That looks like a very good way to
                        solve a problem that many people have written about. Using that script
                        is a very elegant way to do the same thing as the annoying tempo channel
                        or what many people incorrectly use repeat loops for. Good one!
                        • 9. Re: multiple click
                          Level 7
                          This is how I've always done it (ever since the moment I discovered the
                          tempo channel is pretty much worthless) but one does have to be careful with
                          this approach when running at lower tempos. The slower the tempo, whether
                          its from the actuall tempo setting or because of bloated media slowing
                          things down, the less accurate this type of timing is.

                          Craig


                          --
                          Craig Wollman
                          Lingo Specialist
                          Word of Mouth Productions
                          212-928-9581

                          www.wordofmouthpros.com
                          "Dean Utian" <d.utian@unsw.edu.au> wrote in message
                          news:45A97B7D.4A25160B@unsw.edu.au...
                          > Continuing the dicussion on repeat loops and updatestage, I have a demo in
                          > my
                          > Director pages to illustrate a few programming things and alos used it to
                          > illustrate
                          > what not to do.
                          >
                          > One example I have is a 'wait for a certain time' behavior below that
                          > creates a pause
                          > for 2 second (2 sets of 60 ticks)
                          > Frame behavior
                          > on exitFrame me
                          > wait 2*60
                          > end
                          > .
                          > Movie script
                          > -- Wait a certain amount of time
                          > on wait numTicksToWait
                          > startWait = the timer
                          > repeat while (the timer - startWait) < numTicksToWait
                          > updateStage
                          > end repeat
                          > end
                          >
                          > It does much of what has just been said shouldn't be done. Here's a better
                          > of
                          > achieving the same thing and converting it into a behavior where you can
                          > assign the
                          > wait time as you attach it to a sprite:
                          > -- define properties
                          > property pNumMilliSecondsToWait, pStartWait
                          >
                          > -- set the start time at the start
                          > on beginSprite
                          > pStartWait = the milliseconds
                          > end
                          >
                          > on exitFrame
                          > wait pNumMilliSecondsToWait
                          > end
                          >
                          > -- wait custom handler
                          > on wait pNumMilliSecondsToWait
                          > -- loop in the frame until time is up
                          > if (the milliseconds - pStartWait) < pNumMilliSecondsToWait then go the
                          > frame
                          > end
                          >
                          > on getPropertyDescriptionList
                          > pList = [:] -- creates an empty property list
                          > addProp pList #pNumMilliSecondsToWait, [#comment:"Number of milliseconds
                          > to wait:",
                          > #format: #integer, #default:"1000"]
                          > return pList
                          > end
                          >
                          > Besides the changes to milliseconds and restucturing the code, I'm now
                          > using:
                          > if (the milliseconds - pStartWait) < pNumMilliSecondsToWait then go the
                          > frame
                          > so instead of a repeat loop with updatestage, I'm just looping within the
                          > frame.
                          >
                          > regards
                          > Dean
                          >
                          > Director Lecturer / Consultant
                          > http://www.fbe.unsw.edu.au/learning/director
                          > http://www.multimediacreative.com.au
                          >
                          >


                          • 10. Re: multiple click
                            Level 7
                            "forum.macromedia.com" wrote:

                            > ... but one does have to be careful with
                            > this approach when running at lower tempos. The slower the tempo, whether
                            > its from the actuall tempo setting or because of bloated media slowing
                            > things down, the less accurate this type of timing is.

                            Slow tempos will make everything... well, slower. And if it's a bloated media
                            that's slowing down the tempo, then you're already getting an inaccuracy there.
                            Timing based on looping in a frame will always have a maximum inaccuracy of just
                            less than the the time to play 1 frame at the current frame rate. A much better
                            tradeoff than needing to rely on updatestage. And it may be worth noting that
                            behaviors in the Library Palette are written based on frame updates over
                            updatestage. As an example, create a movie at 1 fps, have a sprite with the
                            'Rollover Member Change' behavior attached, and observe the time the sprite
                            takes to change with mouse interaction.

                            regards
                            Dean

                            Director Lecturer / Consultant
                            http://www.fbe.unsw.edu.au/learning/director
                            http://www.multimediacreative.com.au