all groups > flash actionscript > july 2004 >
You're in the

flash actionscript

group:

Get instance name in flash?


Get instance name in flash? mikeaturner25
7/30/2004 8:35:51 PM
flash actionscript: Hi all,

I have a button on stange with an instance name of myButton. What I am trying
to do is get that name (myButton) in the buttons actions. So for example I have
a on press event for that button that does this.

on (press) {
message = "you pressed "+<name>
trace(message);
}

where name would be myButton, but I cant find how to get it. I tried
this._name, but it seems you have to set it to something first. Do you guys
know of a way to get the name of the instance in actionscript?

Re: Get instance name in flash? -]
7/30/2004 8:47:39 PM
myButton.onPress = function() {
//function here
}
Re: Get instance name in flash? mikeaturner25
7/30/2004 9:03:41 PM
Hrm,, well thats not really what I am lookin for.

Maybe this will help show ya what I am trying to do.

on (press) {

for (i in _root)
{
trace(eval(i)._name);
}

}

If you run that code it goes through each instance on stage and finds its
name. So that works fine, but what I want to get the instance name of the
button I clicked.
Re: Get instance name in flash? -]
7/30/2004 9:07:00 PM
Re: Get instance name in flash? mikeaturner25
7/30/2004 9:09:34 PM
No, I am going to put the instance name into a variable and use it later. The
trace was just for me to test to see if it worked or not, and so far I havent
been able to get the instance name of the button.
Re: Get instance name in flash? Jack.
7/30/2004 9:13:12 PM
give the button an instance name and use main timeline code -

btn.onRelease =function(){
message = "you pressed "+this._name; trace(message);
for (i in this._parent) trace(this._parent[ i ]._name);
};

hth
Re: Get instance name in flash? mikeaturner25
7/30/2004 9:20:20 PM
Jack,

That works, but.. here let me tell you what my prob is.

I got 26 buttons on stage each with a name. The names goes like this Button1,
Button2, ect... all the way up to Button26. Right now I have actionscript
inside each one to do pretty much the same thing. Basically I am adding in
movieclips to different levels. So when Button1 is pressed I am adding a clip
to level 1, Button 2 I add a clip to level 2, etc..

What I would like to do is have each of those buttons call one function,
instead of having a bunch of code in each. So when this function is called I
need it to say which button was pressed, then I will know what level to add to.
So, I still need to be able to find the instance of the button that I pressed.

Thanks,
Re: Get instance name in flash? Jack.
7/30/2004 10:25:43 PM
select each button and convert to symbol - movieclip
give each clip an instance name, clip1, clip2..
on the button action in the clip add -

on(press){
str = _name;
arr = str.split("clip");
_parent.loadLevel("movie0"+arr[1]+".swf",arr[1]);
}

on the main timeline -

function loadLevel(mov,lev){
trace(mov+" | "+lev);
loadMovieNum(mov,lev);
};

so clip4 would load movie04.swf to level4,

hth
Re: Get instance name in flash? mikeaturner25
7/30/2004 10:33:46 PM
AddThis Social Bookmark Button