6 Replies Latest reply: Jul 18, 2012 12:40 PM by kglad RSS

    How to obtain instance name of Movie Clip?

    NickelBuckle9 Community Member

      Hello!

       

      Is there a way to get the instance name of a move clip once it's on the stage?  In my dress up game, I need to know which items are on the doll in order to keep them visible.  My drag and drop feature uses an array and currentTarget:

       

       

      var dragArray:Array = [Doll.Drawers.Dress1, Doll.Drawers.Dress2, Doll.Drawers.Dress3, Doll.Drawers.Dress4];
                
                for(var i:int = 0; i < dragArray.length; i++) 
                  {
                          dragArray[i].buttonMode = true;
                          dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
                          dragArray[i].addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
                  }
      
      
      function item_onMouseDown(event:MouseEvent):void 
                {
                     var clip:MovieClip = MovieClip(event.currentTarget);
                     clip.startDrag();
                }
        
      function item_onMouseUp(event:MouseEvent):void 
                {
                     var clip:MovieClip = MovieClip(event.currentTarget);
                     clip.stopDrag();
                     if(clip.hitTestObject(Doll.Skins))
                          {
                                   //Here's where the problem starts!   ----------------------------------------------  //
                                    trace("It's on the doll!");
                          }
                }
      
      

       

      It can successfully run this code.  However, instead of tracing "It's on the doll!", I'd like to turn the currentTarget into it's instance name, which should be "Doll.Drawers.Dress1" etc... and then store that name in an array.

       

      How would I do this?

       

      I've looked into e.target.name, but I keep getting errors...