AsBroadcaster difficulty

Hi, I’m having and issue with AsBroadcaster. I’m trying to get different instances of the same MovieClip to respond to an event. The problem is, I can only ever get one to respond.

Here is the class for the mc broadcasting the event;


class DispatchClass extends MovieClip {

    private static var events:Object; 
    
    public function DispatchClass () {
        events = new Object();
        AsBroadcaster.initialize(events);
    }
    
    public function onRelease () {
        events.broadcastMessage("pressed"); 
    }
        
    public function addListener(listener:Object){
        events.addListener(listener);
    }
}

and here is the class for the receiving MCs:


class listenerClass extends MovieClip {
    
    public function listenerClass () {
        
        var obj1:DispatchClass = new DispatchClass();
        var thisObj = this;
        
        var listener1:Object = new Object();
        listener1.pressed=function(){
            trace("
thisObj = " + thisObj + "
");
        };
        obj1.addListener(listener1);
    }
}

I’m sure it’s something easy I just can’t seem to get around it. Any help would be much appreciated. Thanks, Todd.

The onRelease function of obj1 needs to be called for the event to be broadcast.

class listenerClass extends MovieClip {
    
    public function listenerClass () {
        
        var obj1:DispatchClass = new DispatchClass();
        var thisObj = this;
        
        var listener1:Object = new Object();
        listener1.pressed=function(){
            trace("
thisObj = " + thisObj + "
");
        };
        obj1.addListener(listener1);
		obj1.onRelease();
    }
}

I assume you wanted the event to be broadcast when the user releases the clip with their mouse which will be impossible given your current code since your way of creating an instance of DispatchClass does not allow it to have a visual representation.

Thanks for the Reply.

I’m not sure I explained what is happening correctly. DispatchClass is a class associated with an MC that is being clicked on, that exists on the stage. It isn’t being created dynamically, so I’m not sure what you mean about it not having a visual representation. I need it to broadcast that event to ANY mc on the stage, at any depth, associated with the listenerClass. At this point it only broadcasts the event to the highest level instance of an MC associated with the listenerClass.

Thanks again,
Todd