Paul,

Just my two penn'orth...

For my money, the best way to think about these things is more on a
conceptual level rather than specifically at a code level. What is your
child movieclip? What does it do?

Best example I can think of is off the top of my head is, say, a requester
dialog. Say a simple dialog that just asks the user to confirm Yes or No in
answer to a question. Let's call this ConfirmDialog.

>From a top-level point of view, all your top-level movie clip really cares
about is saying to ConfirmDialog "please pop up, ask a specific question,
and tell me what the user answered". Your movie doesn't care _how_
ConfirmDialog actually achieves that, it just wants to know the answer. So
that gives you a pretty clear indication of the division of responsibilities
- your top-level movie doesn't care whether ConfirmDialog uses buttons,
MovieClips, or a text entry box. It also doesn't care what those things are
called.

That might point you to this sort of implementation (just an example - there
are an infinite number of ways of doing this):
- Parent creates a ConfirmDialog
e.g. var myConfirmDialog:ConfirmDialog=ConfirmDialog(attachMovie(blah));
- Parent tells the ConfirmDialog what question to ask, and what function to
call when the question is answered:
e.g myConfirmDialog.setQuestion("Are you really sure about that?");
     myConfirmDialog.setCallback(Delegate.create(this,onQuestionAnswered));
- Parent hands control over to the dialog:
myConfirmDialog.show();
- Then ConfirmDialog does whatever it wants to internally - creates its own
buttons. It could set event listeners on buttons, could set onRelease etc.
These event listeners will call back into ConfirmDialog's own code. Then
ConfirmDialog will call the parent back with the answer - using
onQuestionAnswered(true) or onQuestionAnswered(false)

Does that make any sort of sense?

Like I said, that's one way of doing it - you could do it with event
listeners, you could do it any old how. The important thing to think about
is the division of responsibilities. It's back to that old black box
metaphor - the containing movie really shouldn't care about the inside of
ConfirmDialog, only that it's putting in specific inputs (the question, the
callback) and getting specific things back out again. Likewise,
ConfirmDialog shouldn't care who's calling it - just that it's getting
particular inputs, doing its own thing, then spitting out an output.

This sort of strategy is the basis of componentisation, and is handy for all
sorts of reasons. It means you could re-use that ConfirmDialog code in any
number of different places. It also means that you could replace the
ConfirmDialog code with some completely different input method (say a
Switch-enabled dialog of some sort) and the parent code wouldn't care that
it had changed.

Of course, one step better is if the parent code doesn't even know it's
calling/attaching a movie clip. If you had a whole ConfirmDialogHandler
class that your parent knows about - the parent just goes:
var myHandler:ConfirmDialogHandler=new ConfirmDialogHandler();
myHandler.ask("Are you sure you want to do this?",Delegate.create
(this,onQuestionAnswered));

Then it's up to ConfirmDialogHandler how it does it - it could pop up a
movie clip, it could read out some text, it could 'phone the user up and
squawk in Morse code at him... err...

Well, you get the idea.

Hope that clarifies it a bit,
  Ian


On 2/21/06, Martin Wood <[EMAIL PROTECTED]> wrote:
>
>
>
> [EMAIL PROTECTED] wrote:
> > This is my first experience use the mailing List so I hope this makes
> sense!
> > My question is more of a conceptual one regarding oop best practises. If
> > I have a class which attaches a clip to the stage how can I attach
> functions
> > to clips nested inside this clip. Putting code on the attached clip?s
> timeline
> > is wrong, I can use;
> >
> > myClip.MyChildClip.onRelease = function() { stuff };
> >
> > It works, but seems fundamentally wrong, as I understood it was bad
> practise
> > to add methods to an object dynamically. Should I make the class listen
> for
> > clicks on the nested clip or is there another solution?
>
_______________________________________________
[email protected]
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

Reply via email to