# Getting and using the instance name of an object

**URL:** https://forum.kirupa.com/t/getting-and-using-the-instance-name-of-an-object/272095
**Category:** flash
**Created:** [October 2, 2008, 12:23am UTC](https://forum.kirupa.com/t/getting-and-using-the-instance-name-of-an-object/272095 "2008-10-02T00:23:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Brent\_Summers](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@Brent\_Summers](https://forum.kirupa.com/u/Brent_Summers)
#### Post date: [October 2, 2008, 12:23am UTC](https://forum.kirupa.com/t/getting-and-using-the-instance-name-of-an-object/272095/1 "2008-10-02T00:23:02Z")

</div>

I am trying to create an easy to extend button class that takes the instance name of the movie clip that was clicked and uses that instance name to tell flash where to go. The problem is that whenever I try to get the instance name of the movie clip that was clicked I just get “root1” instead of the instance name I gave the movie clip.

Here is the basic code below:

var \_destination:String;

characterselect.addEventListener(MouseEvent.CLICK, onClick);

function onClick(Event:MouseEvent):void  
{  
//Sets the destination based on the instance name of the button, this is the part that doesn’t work  
\_destination = this.name;

//Sends the user to destination based on the instance name of the button  
gotoAndStop(\_destination);

//Debug code: Returns “root1”  
trace(\_destination);

//Debug code: This traces “root1”  
trace(this.name);

//Debug code: This returns the “characterselect” which is the instance name of the button  
trace(characterselect.name  
}

THANKS in advance!  
Ben-
