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

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:

on(rollOver) {;

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

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

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) {;
“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… :-\ :frowning: :*(
clear enough?

Im a bit confused, Syko…

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

but you’re sending your code to;

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.

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

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() {

so your first frames actiosn should look like…

_root.myButton.onPress = function() {

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.

humh… oh well… thx guys… :expressionless:

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.

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

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

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

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

it will return myButton.

pom :asian:

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

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