1 Reply Latest reply on Jun 22, 2006 5:52 AM by Newsgroup_User

    onClipEvent problem

    grahamdeuchar
      Hey peeps,

      Right, thanks to the help of a couple of you in here I managed to get a button that scrolls a map while the mouse button is held down. It worked a charm until I tried placing other versions of the button (left, right, up and down obviously) on the stage - the button works on its own, but when placed alongside others with the code all of them break.

      Here's the code:

      onClipEvent(mouseDown) { move=true; }
      onClipEvent(mouseUp) { move=false; }

      onClipEvent(enterFrame) {
      if(move) {
      _level0.map._x = _level0.map._x + 20;
      }
      }

      Any ideas?
        • 1. Re: onClipEvent problem
          Level 7
          grahamdeuchar,

          > I managed to get a button that scrolls a map while the
          > mouse button is held down. It worked a charm until I
          > tried placing other versions ... on the stage - the button
          > works on its own, but when placed alongside others
          > with the code all of them break.

          Let's see that code.

          > Here's the code:

          :)

          > onClipEvent(mouseDown) { move=true; }
          > onClipEvent(mouseUp) { move=false; }

          This may be your problem, right here. onClipEvent() is an event handler
          for movie clips. The "buttons" you're talking about might actually be movie
          clip symbols -- which isn't a problem, so no worries there -- but take a
          look at the ActionScript 2.0 Language Reference entry for onClipEvent.
          Notice at the events this handler handles: none of them pertain to buttons!
          the mouseDown and mouseUp events are *mouse* events, so those occur whenever
          the mouse is clicked or let go; this happens regardless of the mouse's
          location (may not even be on the movie clip/button). So if you have more
          than one of these programmed, you're setting them *all* with every given
          click.

          I think what you want is to trigger each button individually, right?
          Consider the on() event handler instead. This one is made specifically for
          button symbols (though it works on movie clip symbols, too) and features
          press, release, and other events that refer specifically to objects *under*
          the mouse.

          Make sense?

          >
          > onClipEvent(enterFrame) {
          > if(move) {
          > _level0.map._x = _level0.map._x + 20;
          > }
          > }

          But I recommend you get away from onClipEvent() and on() altogether.
          Those are Flash 5-era mechanisms. Since Flash MX (aka Flash 6), it's been
          possible to assign functions directly to button and movie clip events, the
          same way you're directly assigning a value to the _x property of your map
          instance.

          Check out these two articles for details.

          http://www.quip.net/blog/2006/flash/actionscript-20/ojects-building-blocks
          http://www.quip.net/blog/2006/flash/event-handlers-listeners


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