TwelvestoneFlash

Button.prototype ?


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Arsis
 
2003-01-30

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?

jimmyn
 
2003-01-30

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!

Voodoo192
 
2003-01-30

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

Arsis
 
2003-01-30

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

Percival
 
2003-01-31

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. k

HumanCompiler
 
2003-02-01

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.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Button.prototype ?