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

How to obtain instance name of Movie Clip?

Explorer ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

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

Views

2.2K

Translate

Translate

Report

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);
           
...

Votes

Translate

Translate
Enthusiast ,
Jul 18, 2012 Jul 18, 2012

Copy link to clipboard

Copied

     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"


Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

you're welcome.

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Alrighty  ^_^

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

thank you!

Votes

Translate

Translate

Report

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