Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to obtain instance name of Movie Clip?

Explorer ,
Jul 18, 2012 Jul 18, 2012

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.buttonMode = true;

                    dragArray.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);

                    dragArray.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...

TOPICS
ActionScript
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 18, 2012 Jul 18, 2012

use the name property of clip (if that's the movieclip whose name you want):

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.buttonMode = true;
                    dragArray.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
                    dragArray.addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
           
...
Translate
Enthusiast ,
Jul 18, 2012 Jul 18, 2012

     event.target.name

only if you asign the instance name from the properties panel

if you create the object with code you nedd asigna a name:

  var clip:MovieClip = MovieClip(event.currentTarget);

     clip.name="theName"


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2012 Jul 18, 2012

use the name property of clip (if that's the movieclip whose name you want):

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.buttonMode = true;
                    dragArray.addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
                    dragArray.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(clip.name);  // but that won't be Doll.Drawers.Dress1.  it might be Dress1.
                    }
          }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 18, 2012 Jul 18, 2012

Thank you!  Both answers were right.  Can't believe it was so simple, haha.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2012 Jul 18, 2012

you're welcome.

p.s.  please mark esdebon's answer as helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 18, 2012 Jul 18, 2012

Alrighty  ^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2012 Jul 18, 2012
LATEST

thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines