6 Replies Latest reply on May 15, 2007 12:06 PM by Rothrock

    onMouseUp returning name?

    Fen4554 Level 1
      Hi guys,
      I have a bunch of buttons that I want to have do the same thing; pass their instance names to a function that will advanced the play head appropriately. To avoid having to write a ton of .onRelease functions, I'm trying to find a way that I can have a symbol return it's name if the cursor is over it when clicked. I vaguely remember that one of the mouse events would do this by default, passing it through a 'me' type placeholder.

      Something to this effect:
      onMouseUp= function(mySymbol) {
      trace(mySymbol._name);
      }

      Am I way off? It's seems like there should be an easy way to do what I'm talking about.
      Thanks.
        • 1. Re: onMouseUp returning name?
          Rothrock Level 5
          I don't know any way. If anybody else has suggestions…

          However, a ton of onRelease functions isn't generally a problem – if you name or attach your buttons sensibly.

          var home:MovieClip=this;
          for(var i=0;i<100,i++){
          var curClip:MovieClip=home.attachMovie("someLinkage","button"+i,1000+i);
          curClip.onRelease=function(){
          trace(this._name);
          }

          That attaches 100 buttons to the stage (or where ever this is) and will have them trace their name.
          • 3. Re: onMouseUp returning name?
            Fen4554 Level 1
            Yikes, that's lean code. *laughs* And way over my head. I don't have much experience creating and programming objects on the fly using code and for loops. I can understand most of the syntax, but not too sure what everything does. It's only a couple of dozen buttons, I think I should probably stick to manually coding the onRelease. I was just checking if I was missing something (relatively) simple.

            Thanks a lot for your help, and I've filed that nifty function you wrote in that other thread away. Looks very handy.
            • 4. Re: onMouseUp returning name?
              Rothrock Level 5
              Really. This is worth learning. Even if you just have your buttons put on the stage manually during author time. In that case give each one an instance name like, button0, button1, etc. (Dont' start with the numbers, end the names with them.) And let's say you have 12 of them. Then use this:

              numButtons=12;

              for(i=0;i<numButtons;i++){
              var curButton:MovieClip=this["button"+i]
              curButton.onRelease=function(){
              trace("Pressed "+this._name);
              }
              }

              That says numButtons equals 12.

              For all the values of i starting at zero adding one to i each time until it is no longer less than numButtons do the following. (Remember that we started with zero so if there are 12 buttons the biggest number will be button11! Why is it so hard to start counting at zero?)

              Make a variable called curButton that will look inside this object (the current scope) and look for something that has the name of "button" plus whatever value i currently has. PS: This is expecting that your buttons are acutally MovieClips with button like behaviours, not actual buttons.

              Take that curButton and apply an onRelease event handler to it.

              Inside that even handler notice that instead of saying trace(curButton) we say trace(this). That is because we have changed the scope by applying the onRelease to a specific instance.

              This is a technique you will use over and over and over again. If you plan to do much with AS it will be a very useful thing to learn NOW, not LATER! :)
              • 5. Re: onMouseUp returning name?
                Fen4554 Level 1
                Wow, a free lesson! :D That makes perfect sense to me now; I didn't realize you could program functions repetitively like that, and the scope was messing me up. Thanks a ton, I really appreciate you going the extra mile. I realize now how needlessly repetitive my code is. @_@

                Thanks again.
                -Fen
                • 6. Re: onMouseUp returning name?
                  Rothrock Level 5
                  Sure glad to help you out. This really will serve you well.

                  Here is a little exercise for you. Get it to trace the number. So for example button0 will trace "0" and button7 will trace "7".