6 Replies Latest reply on Jun 7, 2006 9:52 PM by TimAndrodney

    Help with hitTest

    TimAndrodney
      I have a movie clip that drags over several other movie clips. These other movie clips have various names and were not created by an array or any other dynamic means. So here's my question. Is there a way to get the name of these movie clips when I drag the original clip over them. I though I could get it with hitTest, but so far no luck.
        • 1. Re: Help with hitTest
          neil manuell Level 1
          if you put the mc that are not dragged in an mc called mcHolder, you could do this:

          dragged_mc.onMouseMove = function () {
          for (var n in mcHolder){
          if(typeof(mcHolder[n])=="movieclip"){
          if(this.hitTest(mcHolder[n]){
          trace(mcHolder[n]._name)
          }
          }
          }
          }

          or if in different locations, you could indeed push them onto an array and loop through that...

          mcArray:Array = new Array()
          mcArray.push(mc_1)
          mcArray.push(mc_2)
          mcArray.push(mc_3)
          //
          dragged_mc.onMouseMove = function () {
          for (var n in mcArray){
          if(this.hitTest(mcArray[n]){
          trace(mcArray[n]._name)
          }
          }
          }
          • 2. Re: Help with hitTest
            TimAndrodney Level 1
            Thanks Fleece, I tried the first way because I can't use an array for this but I get this error:

            **Error** Symbol=periodic_activator, layer=Layer 1, frame=1:Line 6: ')' expected
            if(this.hitTest(_root.periodic_table[n]){

            Total ActionScript Errors: 1 Reported Errors: 1

            Any thoughts?

            Thanks Again.
            • 3. Re: Help with hitTest
              TimAndrodney Level 1
              Actually, I think I got it. ...Maybe. I had a ")" missing in the code.
              • 4. Re: Help with hitTest
                TimAndrodney Level 1
                OK it works, except...

                The clips I need to get the names from are inside a larger movie clip, but also within seperate movie clips in the larger one. Is there a way I could get them two levels in? To use your example, something like:

                for (var n in mcHolder._children){

                The "_children" being the movies that are in the larger movie clip, but contain the clips I'm trying to get the names from.
                • 5. Re: Help with hitTest
                  DJ_Sick_Nick Level 1
                  then do _children.your_mc
                  • 6. Re: Help with hitTest
                    TimAndrodney Level 1
                    Alright, I got it. I was looking at it backwards. Rather having one MC figure out the names of the rest of the MC's, I created an element clip that I placed within each of clips I was trying to get that name for and did the hitTest to the one that's draggable.

                    I should be ashamed of myself...