5 Replies Latest reply on Jun 2, 2006 11:34 AM by Newsgroup_User

    onPress vs onMouseDown?

      I was making multiple dynamic movieclips and trying to assing listeners and onMouseDown functions but couldnt get it to work...it fired all of them at once.

      So I used the onPress instead and everything works fine.

      What is the diff between these two technically? When should I use one vs the other?

        • 1. Re: onPress vs onMouseDown?
          Level 7
          flasheister,

          > I was making multiple dynamic movieclips and trying
          > to assing listeners and onMouseDown functions but
          > couldnt get it to work...it fired all of them at once.

          Start thinking of events in terms of the classes they belong to. There
          are at least two onMouseDown events in ActionScript: one belongs to the
          Mouse class and another belongs to the MovieClip class. Presumably, you're
          using the MovieClip.onMouseDown event. So what does this event refer to?
          It refers to the mouse being clicked. Not being clicked *on* the movie
          clip, necessarily -- just *being clicked*. So if several movie clips have a
          function assigned to their onMouseDown event, then yes, they'll all fire at
          once.

          > So I used the onPress instead and everything works fine.

          That's because MovieClip.onPress (note, there's also a Button.onPress)
          only fires when the mouse is clicked *on* the object in question.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          1 person found this helpful
          • 2. Re: onPress vs onMouseDown?
            2m Level 2
            It is quite simple and not even illogical.

            onPress is fires, when you "press" the clip it is assicioated with - when he pointer hovers over the clip other wise you wouldnt press it.

            on MouseDown fires whenever the mouse(-button) is down(ed), regardless where your pointer is positioned.
            1 person found this helpful
            • 3. Re: onPress vs onMouseDown?
              that makes sense....so even if I use the movieclip.onmousedown that would still fire if I clicked anywhere on the screen right?

              if i understand correctly if i want an event to happen only when I click a particular MC then onPress is the way to go.
              • 4. Re: onPress vs onMouseDown?
                Just one more question on that topic...if I use the onPress, i just assign it to the MC like this.onPress = function () etc...so i can do something when it is pressed.

                Should or in what situation should I use listeners rather that the just assigning an onPress event directly to the MC Seems to just assinging events like onPress, onRollOver, etc. is easiest to just assign them when I attach them to the stage.
                • 5. Re: onPress vs onMouseDown?
                  Level 7
                  flasheister,

                  > Just one more question on that topic...if I use the onPress,
                  > i just assign it to the MC like this.onPress = function () etc...
                  > so i can do something when it is pressed.

                  Sure.

                  > Should or in what situation should I use listeners rather that
                  > the just assigning an onPress event directly to the MC

                  Here's a blog entry on that.

                  http://www.quip.net/blog/2006/flash/event-handlers-listeners

                  In summary: some objects are written to expect event handlers and some
                  are written to expect listeners. You use handlers for the one kind and
                  listeners for the other. The quickest way I can think of to tell which
                  is which is to learch the term "addListener" in the ActionScript 2.0
                  Language Reference. You'll get an awful lot of search results to sift
                  through, but you'll eventually see all the classes that expect this sort of
                  event handling.

                  > Seems to just assinging events like onPress, onRollOver, etc.
                  > is easiest to just assign them when I attach them to the stage.

                  That's just the thing, flasheister, you're not "just attaching them to
                  the Stage." When you use those events as stand-alone actions, you're
                  actually assigning them to a movie clip -- because the main timeline *is* a
                  movie clip. Since that's what you're doing anyway, you may as well use the
                  full syntax. Easier to understand, and you'll be able to "see" what you're
                  doing clearer. My opinion, anyway.


                  David
                  stiller (at) quip (dot) net
                  Dev essays: http://www.quip.net/blog/
                  "Luck is the residue of good design."