# Classes and listeners

**URL:** https://forum.kirupa.com/t/classes-and-listeners/119306
**Category:** Uncategorized
**Created:** [August 13, 2004, 9:50am UTC](https://forum.kirupa.com/t/classes-and-listeners/119306 "2004-08-13T09:50:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![peshay](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@peshay](https://forum.kirupa.com/u/peshay)
#### Post date: [August 13, 2004, 9:50am UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/1 "2004-08-13T09:50:11Z")

</div>

Hi there i want to do the following: make an instance on my stage a broadcaster, create a class called “Module”, in this class define the object as a listener, connect the class to an object on my stage or library.  
Here’s what i have:

```auto

AsBroadcaster.initialize(Main_Md); 
//class definition
Module = function(){ 
Main_Md.addListener(this);
function LoginMessage(){
 this._visible=false;
 }
}; 

Module.prototype = new MovieClip(); 
Object.registerClass("module3", Module); 

```

And i have a button with the action

```auto

on (press) {
_root.Main_Md.broadcastMessage("LoginMessage");
}

```

Why doesnt this work? the object in the library has module3 as linkage, so that cant be the problem…help please

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [August 13, 2004, 10:39am UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/2 "2004-08-13T10:39:20Z")

</div>

you cant yous _function functionName(){}_ syntax to define functions if you’re within the block of another function. You’d need to use _functionName = function(){}_. Thats most of the problem, though with that you should be defining LoginMessage as a prototype function and not within the Module constructor.

```auto
Module = function(){ 
    Main_Md.addListener(this);
};
Module.prototype = new MovieClip(); 

Module.prototype.LoginMessage = function (){
    this._visible = false;
}

```

… also, you’re adding and removing modules a lot, you’d want to rewrite removeMovieClip for them to also remove them from Main\_Md’s listener list.

---

<div class="post-metadata">

### Author: ![peshay](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@peshay](https://forum.kirupa.com/u/peshay)
#### Post date: [August 13, 2004, 10:53am UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/3 "2004-08-13T10:53:37Z")

</div>

Still nothing is working, I think the problem is that the movieclip doesnt get associated with the class.

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [August 13, 2004, 11:01am UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/4 "2004-08-13T11:01:49Z")

</div>

trace a check to find out

trace (clip instanceof Module)

---

<div class="post-metadata">

### Author: ![peshay](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@peshay](https://forum.kirupa.com/u/peshay)
#### Post date: [August 13, 2004, 1:55pm UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/5 "2004-08-13T13:55:11Z")

</div>

What is the usual way to put an instance on the stage in a certain class. instancename Module3 classname Module? O

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [August 13, 2004, 2:32pm UTC](https://forum.kirupa.com/t/classes-and-listeners/119306/6 "2004-08-13T14:32:25Z")

</div>

drag it on from the library or attach movie (in both cases you have to make sure the class is defined first)

[http://www.kirupa.com/developer/oop/](http://www.kirupa.com/developer/oop/)
