# Retrieving Instance Name from Button

**URL:** <https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558>\
**Category:** flash\
**Created:** [February 14, 2003, 5:23pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558 "2003-02-14T17:23:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danneman](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Danneman](https://forum.kirupa.com/u/Danneman)\
**Post date:** [February 14, 2003, 5:23pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/1 "2003-02-14T17:23:06Z")

</div>

Hey!

I created a button, which use various instances of in a menu.

I haven´t dublicated the symbol, so each instance of the button is pretty much identical, except for the Instance Name.

I put a number (1 - 10) in each of the buttons´ Instance Name.

Each button then has a call to a function (which is defined in an included .as file).

The problem Im having is that I want to submit the number in the Instance Name as a parameter in the function-call, but I really dont know what to call the parameter so that it looks the value up.

So, how do I call this value?  
Does my description even make sense?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 14, 2003, 5:40pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/2 "2003-02-14T17:40:31Z")

</div>

it depends how you have it set up.

setting button actions with

buttonName.onPress = function(){  
…  
}

will let you reference the \_name property of that button object, but in putting the code directly on the button

on(press){  
…  
}

the \_name property (this) references the movieclip which the button resides.

in using the first method, the number can be extracted using strig operations on the \_name property. For example:

button10.onPress = function(){  
trace(number(this.\_name.substr(6)));  
}

(6 because button is 6 letters) And from there you can pass that and use that whereever

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 14, 2003, 5:42pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/3 "2003-02-14T17:42:29Z")

</div>

I guess \_name doesn’t work for buttons, but instead you could move that button symbol inside a movie clip, then name the movie clip instance with the numbers. You would then use \_this.name I think or \_parent.\_name, depending where you putting the code.

hth

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 14, 2003, 5:43pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/4 "2003-02-14T17:43:41Z")

</div>

senocular beat me to it, and with a better answer 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 14, 2003, 6:07pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/5 "2003-02-14T18:07:57Z")

</div>

Well, the problem is that all my buttons are named the same (btn\_MENU) - the only thing differing is their Instance Name (1 - 10).

So “this.\_name” doesnt seem to work - perhaps because “\_name” actually contains the name “btn\_MENU” instead of one of the numbers 1-10.

## All the buttons currently contain this code (in the fla-file):

## on (press) { \_root.fn\_menuButtons(3); }

## The includes as-file (with all the code) contains the definition of the function fn\_menuButtons():

## function fn\_menuButtons(instance) { loadMovieNum(“Movie\_” + instance + “.swf”, instance); }

So, when I try using number 3 (for instance - as above) as the parameter passed to the function, it works fine.  
“Movie\_3.swf” is loaded on \_level3.

## But if I exchange the “3” for the code “this.\_name”, it just doesnt work. The Instance Name is not retrieved with this code:

## on (press) { \_root.fn\_menuButtons(this.\_name); }

So what do I replace the “3” with for this to work?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2003, 11:31pm UTC](https://forum.kirupa.com/t/retrieving-instance-name-from-button/13558/6 "2003-02-16T23:31:02Z")

</div>

READ the answers… 🙂

> \*Originally posted by senocular \*  
> \*\*it depends how you have it set up.

setting button actions with

buttonName.onPress = function(){  
…  
}

will let you reference the \_name property of that button object, but in putting the code directly on the button

on(press){  
…  
}

the \_name property (this) references the movieclip which the button resides.

in using the first method, the number can be extracted using strig operations on the \_name property. For example:

button10.onPress = function(){  
trace(number(this.\_name.substr(6)));  
}

(6 because button is 6 letters) And from there you can pass that and use that whereever \*\*  
And I deleted the thread in the other forum.

pom :cowboy:
