I’m not sure I totally understand you, but using prototype will cause that script to be affected for all buttons. The prototype property has to do with OOP, that dreaded Object Oriented Programming. If you want a simpler explanation (I hope it’s simpler ;)), check out a few articles on my website:
http://www.absconditus.com/articles/oop1.htm
http://www.absconditus.com/articles/oop2.htm
That might explain better what the prototype property does.
In any case, know that if you attach anything to the prototype, then it will be available to every instance of that class. So anything attached to
Button.prototype
will be available to every button in your movie. Likewise, anything attached to
MovieClip.prototype
will be available to every MovieClip in your movie.
For example, if you want to make a MovieClip into a button, you simply have to add a click handler function to it, something like onPress, onRelease, onRollOut, etc. E.g. I could turn a clip named mySquare_mc into a button simply by adding this code:
mySquare_mc.onPress = function() {
trace("movieclip has been clicked");
} // end mySquare_mc.onPress()
Try it, you’ll see that now you can move your mouse over the movieclip, at which point it will turn to a hand cursor, and when you click it, the trace will execute. Simple enough.
Now suppose we wanted to turn every movieclip into a button just like this. We simply add the above onPress() function to MovieClip.prototype:
MovieClip.prototype.onPress = function() {
trace("movieclip has been clicked");
} // end mySquare_mc.onPress()
If you do that, you’ll notice that every single movieclip in the .fla will now act like a button…when your mouse passes over it, it turns to a hand cursor, and you can click it and the trace will execute.
So your Button.prototype does basically the same thing. That’s why when you click one button, other’s start looping too.
You’re right, it will be laborious if you remove it and then have to add that code to every button, but it might make things a little clearer.
Another alternative is to leave the prototype code in there, but just make sure that it’s going to do the right thing. Be sure that the code executed in Button.prototype.onRelease() can safely be executed by every button in your movie. If you have code that’s specific for a button, perhaps pass a variable into the function and then use an if statement. Suppose I have two buttons: a_btn and b_btn. I could add a variable to each one:
a_btn.buttonName = "a_btn";
b_btn.buttonName = "b_btn";
Then, inside the Button.prototype, I could something like this:
Button.prototype.onRelease = function() {
trace("button has been clicked"); // do this for all buttons
// determine which button via buttonName variable,
// and execute only some code accordingly
if (this.buttonName == "a_btn") {
trace("this is the a_btn");
} else if (this.buttonName == "b_btn") {
trace("this is the b_btn");
} else {
trace("this is neither a_btn nor b_btn");
} // end if statement
} // end onRelease() method
Something like that might be a way to go.