3 Replies Latest reply on Aug 12, 2010 1:25 PM by kglad

    How do I detect the name of any object pressed?

    DazFaz Level 1

      Hi,

       

      I need to detect the name of any object pressed that is on the stage. This needs to be done by simply pressing the mouse on that particular object on screen.

       

      I tried looking down the Mouse.addEventListener and myObject.target route but did not get very far. Baring in mind that this needs to be done in AS2. I have found a way to do it in AS3 but could not work out how to reverese this as so it works within AS2

       

      Any help would be very much appreciated.

        • 1. Re: How do I detect the name of any object pressed?
          kglad Adobe Community Professional & MVP

          are you looking for code to automatically add mouse handlers to everything on stage?  if yes, do you want those objects to trigger the cursor to change (indicating they can be clicked) or not?  do you already have mouse handlers defined for (some) of the on-stage objects?

          • 2. Re: How do I detect the name of any object pressed?
            DazFaz Level 1

            Hi,

             

            All I need is when the mouse clicks anywhere on the stage, it returns the full absolute path that that object, that has been clicked.

             

            1. are you looking for code to automatically add mouse handlers to everything on stage?  Thats a no

            2. do you want those objects to trigger the cursor to change (indicating they can be clicked) or not?  No idicators if possible

            3. do you already have mouse handlers defined for (some) of the on-stage objects? Thats a yes as some objects will have mouse actions applied e.g. buttons ect.

             

            Thanks for your help.

            • 3. Re: How do I detect the name of any object pressed?
              kglad Adobe Community Professional & MVP

              then the best you can do is to detect movieclip names:

               

              var tl:MovieClip = this;
              tl.onMouseDown = function() {
                  for (s in tl) {
                      if (typeof(tl[s]) == "movieclip" && tl[s]._parent == tl) {
                          if (tl[s].hitTest(_xmouse, _ymouse)) {
                              trace(s);
                          }
                      }
                  }
              };