I have not found great reference on some questions I have about desiging classes and architecture around Flash's architecture. Partly this involves not fully understanding how Flash loads classes:
1. Load/init ordering: When do classes load, and when do static initializers execute? If a class has a static property that is assigned outside a constructor, is this initialized when the class loads (presumably frame 1?) or the first time it is accessed, or what? If class A refers to a static property of class B, how do I ensure that class B is initialized before class A? What if each class refers to a static property of the other class? (These are somewhat silly examples to illustrate the grey area I'm trying to root out.) 2. Timeline/clip context: I am looking for corrections to a few asserstions here: - "this" (always?) refers to a movie clip when the code is outside any class; often the main movie when in the movie's timeline. - "this" refers to an object when inside any class method, with one exception, which is when defining a function within a method, like so: function classMethod() { var loader = new loadVars(); loader.onData = function(text) { this.foo(); /// "this" here does not refer to our class, but as far as I can tell, to nothing } } - "this" is dynamic; within the same function, it may take on different meanings at run time depending on where the function is called. (In which case I'm fuzzy on when and what.) 3. Associating MovieClips and classes: Can a class simply extend MovieClip? And what exactly is happening when a library symbol is linked to a class, at runtime? I tend to favor composition regardless, but there is something ugly to me about having multiple classes which logically correspond to movie clips in the library having to hard-code attachMovie(), which also introduces an architectural problem that seems to break encapsulation. If I have, for instance, 3 classes that handle different aspects of a GUI, or perhaps sprites, and each class in its constructor uses attachMovie() to create graphics from library symbols, if they all attach to _root, then they must make sure to each use distinct depths, which forces each class to know what depths the others are using (or *always* using _root.getNextHighestDepth(), which isn't always desirable). Alternatively, I could place container clips on the stage at author time corresponding to each class, so depths are segregated in this way, but this feels like its adding unnecessary complexity. Finally, if a class uses a singleton pattern, where it has one and only one static instance of itself, but also requires a movie clip, I am confused as to when this instance gets added to the main timeline, which then affects depth stacking order (see question #1). Sorry the last is so verbose. I hope people can clear up my confusion... _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com