Retrieving Instance Name from Button

Hey!

I created a button, which use various instances of in a menu.

I haven´t dublicated the symbol, so each instance of the button is pretty much identical, except for the Instance Name.

I put a number (1 - 10) in each of the buttons´ Instance Name.

Each button then has a call to a function (which is defined in an included .as file).

The problem Im having is that I want to submit the number in the Instance Name as a parameter in the function-call, but I really dont know what to call the parameter so that it looks the value up.

So, how do I call this value?
Does my description even make sense?

Thanks :slight_smile:

it depends how you have it set up.

setting button actions with

buttonName.onPress = function(){

}

will let you reference the _name property of that button object, but in putting the code directly on the button

on(press){

}

the _name property (this) references the movieclip which the button resides.

in using the first method, the number can be extracted using strig operations on the _name property. For example:

button10.onPress = function(){
trace(number(this._name.substr(6)));
}

(6 because button is 6 letters) And from there you can pass that and use that whereever

I guess _name doesn’t work for buttons, but instead you could move that button symbol inside a movie clip, then name the movie clip instance with the numbers. You would then use _this.name I think or _parent._name, depending where you putting the code.

hth

senocular beat me to it, and with a better answer :slight_smile:

Well, the problem is that all my buttons are named the same (btn_MENU) - the only thing differing is their Instance Name (1 - 10).

So “this._name” doesnt seem to work - perhaps because “_name” actually contains the name “btn_MENU” instead of one of the numbers 1-10.

All the buttons currently contain this code (in the fla-file):

on (press) {
_root.fn_menuButtons(3);
}

The includes as-file (with all the code) contains the definition of the function fn_menuButtons():

function fn_menuButtons(instance)
{
loadMovieNum(“Movie_” + instance + “.swf”, instance);
}

So, when I try using number 3 (for instance - as above) as the parameter passed to the function, it works fine.
“Movie_3.swf” is loaded on _level3.

But if I exchange the “3” for the code “this._name”, it just doesnt work. The Instance Name is not retrieved with this code:

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

So what do I replace the “3” with for this to work?

READ the answers… :slight_smile:

*Originally posted by senocular *
**it depends how you have it set up.

setting button actions with

buttonName.onPress = function(){

}

will let you reference the _name property of that button object, but in putting the code directly on the button

on(press){

}

the _name property (this) references the movieclip which the button resides.

in using the first method, the number can be extracted using strig operations on the _name property. For example:

button10.onPress = function(){
trace(number(this._name.substr(6)));
}

(6 because button is 6 letters) And from there you can pass that and use that whereever **
And I deleted the thread in the other forum.

pom :cowboy: