PDA

View Full Version : Making Buttons More Dynamic


holdaway
01-27-2006, 12:17 AM
I have been using a method for a while now for buttons to load a section. Let's say I have a button that is meant to load the home page. I will make a button (let's call it 'homePgBtn'), then place it in a movie clip called 'home'.
Then I write Actionscript on the button that says:

on(press){
_root.gotoAndPlay(this._name);
}

My question is, do I have to place a button in a movie clip for this to work? Is there a way that I can name a button so I don't have to make it inside a movie clip, which DOES have the ability to be named?

Perhaps, a basic question for some, but it's a puzzle that I have been wondering about for a while now.

Also, if I place this code on the root level in a function (where code really should be!) and then call the function from the button, it does not work. Why?

FrodoBaggins
01-27-2006, 08:07 AM
My question is, do I have to place a button in a movie clip for this to work? Is there a way that I can name a button so I don't have to make it inside a movie clip, which DOES have the ability to be named?

A button can be named as well. And you can retrieve the name the same way as with a MC.


Also, if I place this code on the root level in a function (where code really should be!) and then call the function from the button, it does not work. Why?
What code are you using? I have all my button handler functions at root level and it works just fine...

holdaway
01-27-2006, 01:12 PM
Well, I just tried it and it doesn't work. Here are my steps:
1. I create a movie called 'home' and in the linkage it's called 'home' as well. It's not on the stage.
2. I make a new button and place it on the stage. In the INSTANCE NAME box I call it 'home'.
3. On the button I write:
on (press) {
_root.attachMovie(this._name, this._name,0);
}
Doesn't work.....
What am I doing wrong?

FrodoBaggins
01-27-2006, 01:41 PM
I tried it and it works ok for me.
The only thing I can think of is that you unconciously named your button or linkage wrong...