OOP - invoking methods

hi all,

I’m working on this script, where I have my class and it’s methods declared. One of the methods is supposed to set the onRelease functions of some movieclips to invoke one of the classes methods. now usually, you would refer to that method by “this.myFunction”, but in my case, this wouldn’t refer to the object itself anymore. Look at dummy the script below:

myClass = function() {}

myClass.prototype.traceme = function(arg) {
    trace(arg)
}

myClass.prototype.setRelease = function() {
    this.traceme("function is called")
    someMC.onRelease = function() {
        // call traceme method here. 'this.traceme' would look for a function 
        // 'traceme' INSIDE the movieclip, not the class, which is undefined.
    }
}

How would i call traceme once im inside the onRelease question?
Any help would be much appreciated :slight_smile:

ok, i got a reply from the Flashcoders list… i’ll post it as it might help someone else =)

There are a number ways to go about this. The easiest is to set a
referal variable in the button like this:

myClass.prototype.setRelease = function() {

    someMC.parent = this;
    someMC.onRelease = function() {
       this.parent.traceme("this will work!");
    }
}

Or you could use a more OOP approach by using events like this:

myClass.prototype.setRelease = function() {
   ASBroadcaster.initialize(this.someMC);
   someMC.addListener(this);
   someMC.onRelease = function() {
      this.broadcastMessage("buttonEvent","release",this);
   }
}

myClass.prototype.buttonEvent = function(event,button) {
   if(button === someMC)
      this.traceme("this will work too!");
}