[QUOTE=sekasi;2354216]Uuum not to sure about that, I was under the impression that you should try and limit the coupling between classes as much as possible and having each class listening for the other seems to imply tight coupling, no?[/QUOTE]
No, you’re totally right, that sort of tight coupling should be avoided. Interaction should be pretty much vertical, if that makes sense. Classes should interact with their children, and dispatch events to their parents, but they should not be relying on interacting with their siblings - otherwise you’ll end up with inflexible applications that require that precise coupling - which is just not ideal.
[QUOTE=dthought;2354217]Not particularly, I don’t think… but if you did it the way you are suggesting, eg. on your document class
function documentListener(evt:Event):void
{
classAinstance.doSomething();
classBinstance.doSomething();
classCinstance.doSomething();
}
Then that is a really naughty intermingling - even though the document class “manages” things, telling explicit children what to do is, from what I understand, not desirable (though I believe that DisplayObjects may be a slight exception, eg. dealing with those pesky display list children).
Anyway, as I said, that’s just the way I understand things :)[/QUOTE]
Actually, that’s not “naughty” at all. Having an exposed interface (a public method, or set of methods) is a perfectly acceptable and even encouraged practice.
Subclasses should be protected in that no other class should be able to ‘break’ them. Having them be self-contained as possible is ideal, but what is most important is that the class’s methods and variables cannot be abused in any way - i.e. variables cannot be set out of bounds, submethods cannot be called out of order, that sort of thing.
Classes should ideally maintain **internal **sovereignty - but they most certainly can and should interact with their parents and children. The important thing is that they interact in predictable (and well defined) ways.
edit:
As far as the initial question, your setup is fine. The thing I would change is that you should probably fully extract the data from the visual elements. I like to use a Singleton that holds my XML data. My Document class typically instantiates the Singleton and tells it to load the data, and once the data is loaded, it goes about the rest of the application setup - now that the data for the application is available.