1 Reply Latest reply on Jul 17, 2006 10:43 AM by Wolf_van_Ween

    How do I get object name on button click?

    mark.harmon Level 1
      I'm trying to write a generic script that retrieves a button object name and places it in a variable. Something like
      on (release) {
      myObject = this.nameofbuttonclicked;

      any ideas?
        • 1. Re: How do I get object name on button click?
          Wolf_van_Ween Level 1
          Mark, this is possible, but not in the way you've quoted.
          The on(release) actionscript would have to reside on the button itself.
          But the "this" in such a handler (of a Button class object) points to its parent, for instance the _root timeline).
          It also wouldn't make sense. You want that code to work for more than one button, and with on() you would have to manually put that code onto each button separately.
          What you want is to set a mouse event handler from *outside* the button itself. For this you would use the form Button.onRelease = function() { insert your handler here }
          The attached code would go into the first frame of a movieClip (e.g. _root) and it shows how to make each button trace its name when clicked. Hope that makes things clearer....