More importantly, there can always be a debate about what is the 'cleanest'
or best 'OOP' way to do stuff (let's not go down that road again ;) ). But
it's good to remember to do things the way you feel most comfortable with,
without losing readability. (which is easy for me to say, considering I'm
the only flasher :) )
-Meinte
On 2/21/06, Julien Vignali <[EMAIL PROTECTED]> wrote:
>
> Hi Paul and welcome to the list :)
> I am not an OOP expert, but for me it's more natural for a parent class
> to handle its children events, and forward it to its own parent, etc...
>
> Most of the time I use this technique :
>
> import mx.utils.Delegate;
>
> class MainClip extends MovieClip {
> private var nestedClip1:MovieClip;
> private var nestedClip2:MovieClip;
> private var dispatchEvent:Function;
> var addEventListener:Function;
> var removeEventListener:Function;
>
> private function init(){
> mx.events.EventDispatcher.initialize(this);
> nestedClip1 = this.attach("NestedChild", "child1", depth);
> nestedClip1.onRelease = function(){
> // some code here...
> };
>
> // or you could use a Delegate
> nestedClip2 = this.attach("NestedChild", "child2", depth);
> nestedClip2.onRelease = Delegate.create(this, this.onClip2Release);
> }
>
> private function onClip2Release():Void {
> // some code here...
> // forward event to any listeners of MainClip
> dispatchEvent({type:"doSomething", target:this});
> }
> }
>
> You could also create classes for your nested clips that use
> dispatchEvent() and add your main class as a listener of their clicks
> events...
>
> Hope it helps..
> Julien
>
> [EMAIL PROTECTED] a écrit :
> > 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?
> >
> > Cheers,
> > Paul
> >
> > ___________________________________________________________
> >
> > Tiscali Broadband from 14.99 with free setup!
> > http://www.tiscali.co.uk/products/broadband/
> >
> >
> > _______________________________________________
> > [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
> >
> _______________________________________________
> [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
>
_______________________________________________
[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