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...
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);
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"
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. } }
Copy link to clipboard
Copied
Thank you! Both answers were right. Can't believe it was so simple, haha.
Copy link to clipboard
Copied
you're welcome.
p.s. please mark esdebon's answer as helpful.
Copy link to clipboard
Copied
Alrighty ^_^
Copy link to clipboard
Copied
thank you!