Classes and listeners

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:


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


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

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.

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.

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

trace a check to find out

trace (clip instanceof Module)

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

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/