You can neither receive mouse events on a symbol (i.e. a Class
), nor dispatch any event from it. So that is out of the question.
You could create a new Sprite symbol, place your custom Button in it, and then add a listener in a frame script inside of that Sprite - but that is really messy.
The cleanest way to do this is to add a listener for Event.ADDED to the stage - which is caught whenever any new instance of DisplayObject
is added anywhere in the display list - and make a handler function add the appropriate listener to each instance of your special button:
function onInstanceAdded( event:Event ) : void {
if( event.target ) is MySpecialButton
event.target.addEventListener( MouseEvent.CLICK, onSpecialButtonClick );
}
function onSpecialButtonClick( event:MouseEvent ) : void {
doMagicStuffHere();
}
stage.addEventListener( Event.ADDED, onInstanceAdded );