OK - I think if I can get an answer to this, I’ll finally be in business. See attached clip_test_setup2.zip.
The example is purposefuly left unfinished and I’ve tried to keep it as simple as possible.
What the built swf currently does:
- Rolling over either the blue or green squares send events to the controller.
- Controller tells the model to do something (I believe that the views are actually supposed to provide that data, not the controller - in my realworld app I’m just passing evt.target.name as the “custom” data).
- Model sends an event out, notifiying that its been updated
- All views receive the update notification, but custom handline by each type of view.
What I need to figure out:
- First, unhide the second layer in BlueClip, which has embedded within it four circles. Note that the circles absolutely must have custom-made instance names on the stage. In my realworld app, those instance names are used by the model to reference which pieces of data it needs to update.
- Help me implement the composite pattern. Component.as and Composite.as are included, almost verbatim from O’Reilly’s book with the event handling commented out.
The final rules I’m trying to apply:
a) The circles are graphically bound to their parent, the BlueClip. They have custom-made instance names required by the model. In my realworld app, the model is importing data that is guaranteed to directly co-relate to the circles’ movieclip instance names, so I don’t even need to hold their instance names anyplace as a referenced list (i.e. modelData[circleInstanceName].someData).
b) Either BlueClip and/or GreenClip can be added/removed at any point in time by the Document class or more likely, the Controller. When that happens, the model will have already imported a different set of data. Its OK that removing BlueClip removes all of its children.
c) The circles are each uniquely named and uniquely drawn, but are all typed of a single base class. For instance, they each might somehow send a different number to the model. Again, in my realworld app, I just need to get evt.target.name (of the child circles themselves) to the model, and that’s all the model needs to update the data.
d) GreenClip and BlueClip and all of BlueClips Circles should ALL receive “aNumberUpdated” and “bNumberUpdated” notifications from the model, each with their own handling - tho the circles would all handle in the same way.
e) Only the CIRCLES of BlueClip should handleMouseOverClip and send the event. GreenClip itself shoud also be able to send it, but BlueClip itself doesn’t need to.
f) BlueClip has no direct interaction with the user, but it would need to receive and handle events from the model in its own unique way while still passing those down to its circle children unharmed.
g) In my realworld app, I can’t have something where separate AS files are manually being made for each of the unique Circles. Imagine hundreds of these being embedded into BlueClip. I really dig that Flash creates these automatically!
As you can see, GreenClip and BlueClip are vastly different, and while the circles in BlueClip might appear different, they all behave the same way.
My confusion, for the most part, is “what” BlueClip needs to be in the Composite pattern. If its a Component, do I need to create a rootview that parents both BlueCircle and GreenCircle? Do the Circles then simply extend and override BlueClip or are they Components themselves? If the Circles are Components, how do I send them the model via constructor since they are being instantiated when the swf is made, not by any of my actionscript? Finally, how should the circles be setup in the Linkage properties?
I know that’s alot for someone to plow through, but any thoughts on moving forward with this simple example would be much appreciated. Perhaps I’m making it more complicated than it needs to be, but IMHO, this would be a very useful response to anyone who is plagued by design patterns, AS3, and “the old way” of drawing in Flash.
And if you got this far, thanks at least for reading!