Say I’m building a thing with a main class and several child classes:
[LIST]
[]City
[]Block
[]Building
[]Floor
[/LIST]
Is it bad practice to dispatch the same custom event type upward from the bottom-most child to the top-most, like this:
// City
block = new Block();
block.addEventListener(CustomEvent.FOOBAR, blockEventHandler);
function blockEventHandler(c:CustomEvent) {
// so something
}
// Block
building = new Building();
building.addEventListener(CustomEvent.FOOBAR, buildingEventHandler);
function buildingEventHandler(c:CustomEvent) {
dispatchEvent(new CustomEvent(CustomEvent.FOOBAR));
}// Building
floor = new Floor();
floor.addEventListener(CustomEvent.FOOBAR, floorEventHandler);
function floorEventHandler(c:CustomEvent) {
dispatchEvent(new CustomEvent(CustomEvent.FOOBAR));
}
// Floor
dispatchEvent(new CustomEvent(CustomEvent.FOOBAR));
Just to clarify, notice that in each of the three child classes I’m dispatching the same type of custom event.
Or is it better to create a different event type for each?