
Код:
package Classes{
import flash.events.Event;
import Classes.ConstructorEvents;
import flash.display.Sprite;
public class ConstructorContainer extends Sprite {
public function ConstructorContainer() {
addEventListener(ConstructorEvents.BTN_STATUS, broadcastMess);
for (var i:uint = 0;i < this.numChildren;i++) {
var child:MenuButton = this.getChildAt(i) as MenuButton;
if (child) {
child.addEventListener('broadcastAll', child.broadcastAllHandler);
}
}
}
public function broadcastMess(evt:Event)
{
dispatchEvent(new ConstructorEvent('broadcastAll'));
}
}
}
}

Код:
package Classes{
import flash.events.Event;
public class ConstructorEvent extends Event
{
public static const BTN_STATUS:String = "btnStatus";
public static const BROADCAST_ALL:String = 'broadcastAll';
public var menuButton:MenuButton;
public function ConstructorEvent (type:String, bubbles:Boolean = false) {
super(type, bubbles);
}
}

Код:
package Classes{
import flash.display.MovieClip;
import flash.events.Event;
import Classes.ConstructorEvents;
public class MenuButton extends MovieClip
{
public function MenuButton()
{
addEventListener(ConstructorEvents.BTN_STATUS,onStatus);
addEventListener("click",onClick);
addEventListener("rollOver",onRollOver);
addEventListener("rollOut",onRollOut);
}
private function onClick(evt:Event):void
{
var event:ConstructorEvent = new ConstructorEvent(ConstructorEvent.BTN_STATUS, true);
dispatchEvent(event);
}
private function onRollOver(evt:Event):void
{
}
private function onRollOut(evt:Event):void
{
}
public function onStatus(evt:Event):void
{
trace(evt.target.name);
}
public function broadcastAllHandler(event:ConstructorEvent):void {
if (event.menuButton != this) {
trace(this.name);
}
}
}
}