# Reference button from within the function it calls?

**URL:** https://forum.kirupa.com/t/reference-button-from-within-the-function-it-calls/261093
**Category:** flash
**Created:** [May 23, 2008, 1:46am UTC](https://forum.kirupa.com/t/reference-button-from-within-the-function-it-calls/261093 "2008-05-23T01:46:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ibsen](https://avatars.discourse-cdn.com/v4/letter/i/c67d28/32.png) [@ibsen](https://forum.kirupa.com/u/ibsen)
#### Post date: [May 23, 2008, 1:46am UTC](https://forum.kirupa.com/t/reference-button-from-within-the-function-it-calls/261093/1 "2008-05-23T01:46:52Z")

</div>

I’m making a function to be called by different buttons, and I want the function also alter the appearance of the button itself. But I don’t know how to refer to the button from within the generic function.

```auto
function set_style() {
	trace('this: '+this);
	trace('_parent: '+_parent);
	trace('_root: '+_root);
	trace('_level0: '+_level0);
//none of these produce the name of the button
}
bt1.onRelease = function() {
	set_style();
	trace('[from button] this: '+this);
//this produces the name of the button
};

```

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [May 23, 2008, 3:34am UTC](https://forum.kirupa.com/t/reference-button-from-within-the-function-it-calls/261093/2 "2008-05-23T03:34:14Z")

</div>

What makes that function generic?

Anyway, you can use:

```auto
set_style.apply(this);

```

Using _apply_ allows you to select the scope in which the function is called. You could also pass a reference to the button into _set\_style_.

---

<div class="post-metadata">

### Author: ![keitai](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@keitai](https://forum.kirupa.com/u/keitai)
#### Post date: [May 23, 2008, 7:58am UTC](https://forum.kirupa.com/t/reference-button-from-within-the-function-it-calls/261093/3 "2008-05-23T07:58:11Z")

</div>

```auto

function set_style(mc) {
mc = this;
	trace('this: '+this);
	trace('_parent: '+_parent);
	trace('_root: '+_root);
	trace('_level0: '+_level0);
//none of these produce the name of the button
}

bt1.onRelease = function() {
	set_style(this);
	trace('[from button] this: '+this);
//this produces the name of the button
};

```
