# Button.\_name -- doesnt work

**URL:** <https://forum.kirupa.com/t/button--name-doesnt-work/65741>\
**Category:** flash\
**Created:** [September 29, 2004, 6:51am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741 "2004-09-29T06:51:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashishchandras](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@ashishchandras](https://forum.kirupa.com/u/ashishchandras)\
**Post date:** [September 29, 2004, 6:51am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/1 "2004-09-29T06:51:35Z")

</div>

Hi,

I am using Flash MX 2004, Falsh Player 7 and AS version is 2.0  
I want to get my buttons instance name when clicked on it, how do get that.

Script written on my button:

on(release) {  
trace(this.\_name) //my alert window displays blank :sure:  
};

Any idea y i am not getting it

* * *

aShIsH

---

<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:** [September 29, 2004, 7:53am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/2 "2004-09-29T07:53:43Z")

</div>

It works if you put on(release) {  
trace(yourinstancename.\_name)  
}

---

<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:** [September 29, 2004, 8:48am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/3 "2004-09-29T08:48:58Z")

</div>

> [@Ubik](#):
>
> It works if you put on(release) {  
> trace(yourinstancename.\_name)  
> }

Hi

Thanx for ur reply. But I dont have only a single button their, there could be more than that. Then in that case I want to call a funtion and pass a parameter to it based on the button pressed.

If I have to wirte instancename with \_name then does it make sense of using it? What u say?

I hope u understand what i am trying to say :sure:

* * *

aShIsH

---

<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:** [September 29, 2004, 10:24am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/4 "2004-09-29T10:24:48Z")

</div>

The scope of the static on(release) handler is the parent of the instance it was assigned to. Therefore, if you have:

```auto

on(release){
trace(this._name);
}

```

Then this will refer to the parent of the instance this was placed on. So if your button is on the main timeline, this will refer to the main timeline (\_root), and not the button itself. Because \_root’s \_name is set to nothing by default, you get a blank trace.

As Ubik said, to fix this you need to use

```auto

on(release){
trace(instance_name._name);
}

```

Where instance\_name is the instance name of your instance. So say your button has the instance name ‘foo’, then you’d use this:

```auto

on(release){
trace(foo._name);
}

```

This is actually the same as:

```auto

on(release){
trace(this.foo._name);
}

```

But you can omit the this, unless really needed. This code is pretty useless though, because you need to go look at the instance name anyway, so it’s no use to first target foo, and then ask for it’s name, which is obviously foo too. You’d rather want to use dynamic event handlers instead:

```auto

foo.onRelease = function(){
trace(this._name);
}

```

In dynamic event handlers, this does reference the instance, because it’s a method of the instance.

---

<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:** [September 29, 2004, 10:28am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/5 "2004-09-29T10:28:48Z")

</div>

if you want this.\_name to work, then you need to use

buttonInstanceName.onRelease = function(){  
// buttons\_Name = this.\_name;  
}

---

<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:** [September 29, 2004, 11:36am UTC](https://forum.kirupa.com/t/button--name-doesnt-work/65741/6 "2004-09-29T11:36:51Z")

</div>

> [@senocular](#):
>
> if you want this.\_name to work, then you need to use
> 
> buttonInstanceName.onRelease = function(){  
> // buttons\_Name = this.\_name;  
> }

Hi

Thanx for your replies.

* * *

aShIsH
