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?
myButton.onPress = function() { //function here }
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.
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.
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
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,
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
Don't see what you're looking for? Try a search.
|