10 Replies Latest reply on May 11, 2007 9:17 PM by isaacewing

    Get name of instance under mouse

    Rothrock Level 5
      I've got a Mouse listener checking for all the onMouseUps. Is there a way to find out the name of any instance (if any) that the mouse is over when it comes up?

      The only way that pops into my head is to iterate through all the instances on stage at the moment, if it is a movieclip (the only objects I'm interested in) do a hit test to see if the pointer was on it, and then use its name.

      Not to hard, but just wondering if there is a more elegant way that I'm just not seeing.
        • 1. Re: Get name of instance under mouse
          Level 7
          How about DisplayObjectContainer.getObjectsUnderPoint() ? Haven't tried it,
          but looks promising.


          • 2. Re: Get name of instance under mouse
            Rothrock Level 5
            Good idea, but this project (and it is part of a large project) is well underway with AS2. I will file that in the back of my head for the future. :)

            Basically I'm making some little kid games. I want to check if they are repeatedly clicking on some disabled movieclip. If they do it some arbitrary number of times I want to bring up a dialog/coach who tells them that the button is disabled.

            Here is what I've come up with. This is only the test part, there is also a part that counts up the number of trues I get and if it goes over a certain limit starts the coach sequence. If you have any feedback, please let me know. Thanks.
            • 3. Re: Get name of instance under mouse
              Level 7
              That looks reasonable for what you need to do. I think I would have
              approached it in the much same way.

              BTW, you don't need that break statement after the return.


              • 4. Re: Get name of instance under mouse
                dr_ross Level 1
                Roth, you could go use the really old MovieClip._droptarget property on a tiny _alpha'ed out movieclip you start dragging around on mouse down, use a onMouseMove handler mixed with an updateAfterEvent on it and that'll keep the resolution up.

                Then all you need to do is eval the value of _droptarget on mouse up and disable that.
                I'm sure it'll be faster than enumerating through all the objects on Stage, although of course it has its limitations, especially if you're after all the objects stacked on each other.

                Anyways, hope that helped

                • 5. Re: Get name of instance under mouse
                  Rothrock Level 5
                  Thanks for the inputs.

                  dr_ross I thought of the _droptarget, but there are other things I might be dragging and I think that would complicate things. There aren't that many things on the stage and these are not high speed games so I think it makes sense.
                  • 6. Re: Get name of instance under mouse
                    isaacewing Level 1
                    hey buddy, you could use a on(rollover) action. on the section for the movie clips you want to have that action on, add the code below and it will automatically trace the name of the movie.

                    on(rollOver){
                    trace("you just scrolled over the moviecip: "+this.name)
                    }

                    try that and let me know what you think! (if that is what you were asking)
                    • 7. Re: Get name of instance under mouse
                      Rothrock Level 5
                      Thanks for the suggestion, but that is not quite what I'm trying to do.

                      I have buttons (acutally movieclips) that are disabled that I want to check if a little kid is just clicking it over and over.

                      Since they are disabled an onRollOver (I prefer to use that kind of notation) won't work.
                      • 8. Get name of instance under mouse
                        willrose
                        I'm not sure if it would be any more elegant, but could you fake that the movieClip was disabled instead of actually setting its .enabled property to false? Something like this maybe...

                        • 9. Re: Get name of instance under mouse
                          Rothrock Level 5
                          willrose – thanks for that idea. I will think about it. But there can be several different types of buttons and I have to come up with a solution that other developers can easily work into their existing files.

                          I'll give it a thought.

                          and thanks everybody.
                          • 10. Re: Get name of instance under mouse
                            isaacewing Level 1
                            wait a sec rothrock... by you saying... you want to come up with something that other developers can use... so would you prefer or think it would be best if you created a component that did that action for you and allows for a .... i guess an array or 2d array would work best for storing the data... i am sorry my input was not correct, i think creating a component would work best... what do you think about that... if that is the case i will be happy to help with that unless i misunderstood the question.