# OOP - invoking methods

**URL:** <https://forum.kirupa.com/t/oop-invoking-methods/25455>\
**Category:** flash\
**Created:** [July 13, 2003, 12:29am UTC](https://forum.kirupa.com/t/oop-invoking-methods/25455 "2003-07-13T00:29:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ahmed](https://forum.kirupa.com/u/ahmed)\
**Post date:** [July 13, 2003, 12:29am UTC](https://forum.kirupa.com/t/oop-invoking-methods/25455/1 "2003-07-13T00:29:59Z")

</div>

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:

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 13, 2003, 12:53am UTC](https://forum.kirupa.com/t/oop-invoking-methods/25455/2 "2003-07-13T00:53:21Z")

</div>

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:

```auto
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:

```auto
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!");
}

```
