This works:function loader(path) { trace(path); }where the buttons calls the function:on(press) { _root.loader("file.swf"); }But this doesn't:Button.prototype.loader = function(path) { trace(path); }where the buttons calls the function:on(press) { loader("file.swf"); }Why?
i'm not positive on this, but i think it's because the on() {} construct assumes the scope of whatever movieclip the button is in. so if your button is on _root, any code between an on() {} call will use root's scope....which is why your first example works.
prototyping to the button object will most likely force you to use the MX callback functions so this on(press) { loader("file.swf"); }could go to thisthis.onPress = function() { this.loader("file.swf"); }because everything is kept in the scope of the button object.
the subtle scope difference between on() {} for buttons and onClipEvent() {} for movieclips was definitely something i never liked about them in the flash 5 days.
hope this helps!
you could also try using
function loader(path) { trace(this.path); }
As jimmyn said it is something to do with the scope, but what, I'm not sure.
hope this helps
I hears ya!
I understand what you are saying but don't understand why it works in such a way. I figured that prototype kind of braodcasts a method to all instances of a class and the scope remains withing each instance (like MCs)... except for buttons huh :confused:
starts fight between prototype and proto
Do you mean like this:
Button.prototype.blah = function(stringy){ trace(stringy); } But1.onRelease = function(){ this.blah("oooooooo"); }
that works but
Button.prototype.blah = function(stringy){ trace(stringy); } But1.onRelease = function(){ blah("oooooooo"); }
This does not. I tend to always use "this" now. Seems things don't like to work sometimes without it when they really should. 
the second one doesn't work because technically you're calling blah on wherever your code is. More than likely, _root.blah, by putting this in front of it, makes it so you're calling it for the button.