This is a tricky one, purists would say to to go with the array looping method, as with this method it would be possible to cut out the view out of the MVC and still have the system working (which is a good test of any system). However, if you are working with the events you can cut some corners with event bubbling and strict typing.
For example if we assume you make a custom event called CloudEvent
that has a property called cloud
that contains a reference to the dispatching CloudSprite
, then as long as the event bubbles by default, you don t need to add an event listener to each one, just to the DisplayObjectContainer
which holds them (which I am imaginatively calling CloudContainer
). This way the event bubbles up and you only have to add one listener, and don t have to worry about managing listeners on child items.
public function CloudContainer()
{
super();
addEventListener(CloudEvent.CHANGE, cloudChangeHandler);
}
private function cloudChangeHandler(evt:CloudEvent):void
{
var cloud:CloudSprite = evt.cloud;
cloud.update();
}
Hope this helps