2 Replies Latest reply on Sep 2, 2006 11:54 AM by southbeachbum

    Navigation: assigning variables to clips?

    southbeachbum Level 1
      Hey all

      Basically I've got 9 clips, any of which could have been selected prior to a mouse event. I want my mouse event to know which clip was previously selected. Do I assign a variable to each of my clips? How do I do that? Inside the event handler, or before it...

      Any input sooooooooo appreciated...
        • 1. Re: Navigation: assigning variables to clips?
          Level 7
          southbeachbum,

          > Basically I've got 9 clips, any of which could have been
          > selected prior to a mouse event.

          Okay.

          > I want my mouse event to know which clip was previously
          > selected.

          Gotcha.

          > Do I assign a variable to each of my clips? How do I do
          > that? Inside the event handler, or before it...

          Well, you *could* assign a variable to each clip, but if all you want to
          know is "which clip was selected last," that's only one piece of
          information -- so you only need one variable. I would declare one variable
          in the timeline that houses each of your clips. If, for example, these
          clips are in the main timeline, then you could put the following code into
          frame 1 of the main timeline:

          var lastSelected:MovieClip;

          That one line uses the var statement to declare a varaible. The next
          word, lastSelected, is the name of the variable, which is arbitrary (but
          lastSelected makes sense). The :MovieClip part means that this variable is
          intended to refer to a movie clip instance, rather than to a string, a
          number, an array, or some other datatype.

          The variable doesn't yet contain any information, but it is *set up* to
          contain information of a certain kind.

          Now, I have no idea how you're handling your mouse events. My guess is
          that you're using on() or onClipEvent(). You *might* be assigning a
          function to the MovieClip.onRelease event of each instance. That's the
          "newer" way of doing things (new since Flash MX [aka 6]), but many people
          continue to use the old way.

          In any case, whenever you click a movie clip, have its event handler set
          the value of lastSelected to itself. e.g.

          on(release) {
          lastSelected = this;
          // other instructions here
          }

          or

          clipInstanceName.onRelease = function() {
          lastSelected = this;
          }

          With me? That provides a value for the variable we set up to contain
          exactly this sort of reference. Of course, you said you also want to
          *check* that variable, and you'll probably want to do that before you set
          it.

          on(release) {
          if (lastSelected == clipA) {
          // do something
          }
          if (lastSelected == clipB) {
          // do something
          }
          // etc.
          lastSelected = this;
          }

          or

          clipInstanceName.onRelease = function() {
          if (lastSelected == clipA) {
          // do something
          }
          if (lastSelected == clipB) {
          // do something
          }
          // etc.
          lastSelected = this;
          }


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Navigation: assigning variables to clips?
            southbeachbum Level 1
            I'm just going to go ahead and set the movie up and then test this. David, thanks so much for the thorough response... I'll show you the result shortly.
            sbb