# Instance name of a button... wut's it good for?

**URL:** <https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484>\
**Category:** Uncategorized\
**Created:** [August 11, 2002, 12:33pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484 "2002-08-11T12:33:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![andr\_in](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/andr_in/32/37_2.png) [@andr\_in](https://forum.kirupa.com/u/andr_in)\
**Post date:** [August 11, 2002, 12:33pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/1 "2002-08-11T12:33:34Z")

</div>

Ya know in Flash MX you can assign an instance name to a button… well what’s it good for???  
I wanted to make a button that when you rollover it then an animation inside it will play… (of course I have a stop() action on the first frame of the mc)  
Let’s say that the inst-name of the button is “btn” and the mc inside it “mc”  
so I kinda put it like this:

```auto
on(rollOver) {
_root.btn.mc.play();
}

```

but nothin’ :-\  
I mean… If I can’t use it like this… What’s it good for???  
:-\ :-\ :-\

---

<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:** [August 11, 2002, 1:07pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/2 "2002-08-11T13:07:46Z")

</div>

I’m sure there are many other opinions on this one, but I’ve found that instance names for graphic objects a great benefit for consolidated code.

In flash 5, we had to attach button scripts directly to the instance. Now, all the code can be written in one place, and updated very easily.

But… buttons still have no timelines, which limits them. I’m not sure exactly what you’re trying to achieve… Could you explain it, or attach the fla?

Good luck

---

<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:** [August 11, 2002, 4:27pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/3 "2002-08-11T16:27:08Z")

</div>

well… I like have a movieclip inside the button… in all the frames (up, over, down, hit)  
and inside that movieclip there is an animation, and in the first frame there is stop() action so it won’t play it by itself…  
and on the button I have the actions  
on(rollOver) {  
\_root.btn.mc.play();  
}  
“btn” is the instance name of the button, and “mc” is the instance name of the mc.  
so if I rollOver the button, it should play the anim inside the mc… but it won’t… :-\ ☹ :\*(  
clear enough?

---

<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:** [August 11, 2002, 5:30pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/4 "2002-08-11T17:30:41Z")

</div>

Im a bit confused, Syko…

if you have a stop action on frame 1 of your mc

but you’re sending your code to

\_root.btn.mc.gotoAndplay();

when it goes to frame 1 of your mc, it will stop. Not play.

Now, if you tell me you are sending it to frame 2, then… let’s talk.

---

<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:** [August 11, 2002, 6:46pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/5 "2002-08-11T18:46:12Z")

</div>

first of all… it’s no gotoAndPlay()  
second of all it won’t work with gotoAndPlay(2) too… or …toAndPlay(1);… or play();  
:-\

---

<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:** [August 11, 2002, 6:54pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/6 "2002-08-11T18:54:20Z")

</div>

Instance names for buttons comes in handy.

Here try this…

Create a movie with 2 frames. each frame with a stop() action.

Create a button on the first frame. Call it myButton in the instance area.

In the second frame, just draw some lines and crap.

Go back to the actions of the first frame and insert

\_root.myButton.onPress = function() {  
gotoAndStop(2)   
}

so your first frames actiosn should look like…

```auto

_root.myButton.onPress = function() {
	gotoAndStop(2)	
}
stop();

```

I think the point of button instnace names is to be able to to execute a button through frame actions instead of on the button itself, but I am not 100% on that.

---

<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:** [August 12, 2002, 6:22am UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/7 "2002-08-12T06:22:54Z")

</div>

humh… oh well… thx guys… 😑

---

<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:** [August 12, 2002, 6:45am UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/8 "2002-08-12T06:45:34Z")

</div>

Why dont you just put the animation in the OVER frame of the button and not have a stop action on the MC. Then when the mouse rolls over the button will advance to the frame with the MC ready to play. I am a bit confused with what you are trying to accomplish - but from what I got this should do it without any code.

---

<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:** [August 12, 2002, 1:30pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/9 "2002-08-12T13:30:26Z")

</div>

A few things…

Syko \>\> why do you go back to the \_root to target your movie clip, when all you have to do is play it from where you are?

LostinBeta \>\> you’re right on that one. Instance names of buttons are used with dynamic event handlers. For instance, if you try to name a button **myButton** and then put the code

```auto
on (press) {trace (this._name);}

```

it will return nothing. But if you put a dynamic event handler

```auto
myButton.onPress=function(){trace (this._name);}

```

it will return _myButton_.

pom :asian:

---

<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:** [August 12, 2002, 4:37pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/10 "2002-08-12T16:37:35Z")

</div>

Woo Hoo, I am learning this AS stuff pretty quick.

---

<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:** [August 12, 2002, 5:01pm UTC](https://forum.kirupa.com/t/instance-name-of-a-button-wuts-it-good-for/4484/11 "2002-08-12T17:01:22Z")

</div>

Ryall -\> That was just an example… Actually I’m creating a more complicated thing!:cool:  
:cool:
