It's also very
certain to drive another coder potentially working with your code in
the future into insanity...

I don't know.  Sometimes that's a valid reason to do things like that. :)

As powerful as being able to do that is, it's one of those "features"
of Flash that always scares me.  I tend to think in terms of having my
code being used by someone else, and I don't like the ability of other
people to mess with my stuff at runtime and potentially break my
invariants, though maybe I just have trust issues.

Then again, that ability is the *only* reason I was able to get code
someone else gave me to actually work...

  -Andy

On 3/19/07, Mark Winterhalder <[EMAIL PROTECTED]> wrote:
> To be honest, I'm not really sure what is better. Certainly the Director way
> is a lot more flexible - you can generate and swap ancestors on the fly,
> which I think is pretty cool, a bit like inheritance via composition.

If you're not using AS3 yet, you can do it. You can set an object's
__proto__ property to any object (not just a class prototype!):

class Foo {
    public function greet () : Void {
      trace( "hello" );
   }
}

class Bar {
    public function greet () : Void {
      trace( "g'day" );
   }
}

class Foobar extends Foo {
   // ...
}

var foo = new Foo();
var bar = new Bar();
var foobar1 = new Foobar();
var foobar2 = new Foobar();
var foobar3 = new Foobar();

foo.greet(); // "hello"
bar.greet(); // "g'day"
foobar1.greet(); // "hello"
foobar2.greet(); // "hello"
foobar3.greet(); // "hello"

// now, let's let foobar1 extend Bar instead...
foobar1.__proto__ = Bar.prototype;
foobar1.greet(); // "g'day"
foobar2.greet(); // "hello"
foobar3.greet(); // "hello"

// foobar1 now has lost any other methods and properties previously
inherited from Foobar

// let all instances of Foobar extend Bar
Foobar.prototype.__proto__ = Bar.prototype;
foobar1.greet(); // "g'day"
foobar2.greet(); // "g'day"
foobar3.greet(); // "g'day"

// foobar2 and foobar3 still inherit methods and properties from
Foobar, foobar1 of course doesn't unless you set it's __proto__ back
to Foobar.prototype

// now, add a generic object to the prototype chain:
var baz = { greet: function () { trace( "how's it goin'?" } };
foobar1.__proto__ = baz;
foobar1.greet(); // "how's it goin'?"

// foobar1 now can't do anything else but greet(), let's let baz
"extend" Foobar to give it back the other Foobar methods:
baz.__proto__ = Foobar.protoype;

Fun stuff, huh? However, I strongly recommend not to use this other
than for purely educational purposes. If you feel like you have to
mess with the prototype chain at runtime, odds are there is something
you're doing wrong, and you should rethink your design. It's also very
certain to drive another coder potentially working with your code in
the future into insanity...

Mark



On 3/19/07, Karina Steffens <[EMAIL PROTECTED]> wrote:
> Danny, I think what Ron means is, you don't instantiate the class _and_ the
> super class, as you would with Director.
>
> As you know (and for anyone that isn't familiar with it), in Director the
> "ancestor" property is an instance of the superclass, residing within an
> instance of the subclass (a bit like a Russian Doll!) - but in Flash you
> don't get two instances within each other, but just a single hybrid of all
> the classes in the inheritance chain.
>
> To be honest, I'm not really sure what is better. Certainly the Director way
> is a lot more flexible - you can generate and swap ancestors on the fly,
> which I think is pretty cool, a bit like inheritance via composition.
>
> Actually if you go back to the metaphor, the Chrysler PT Cruiser in Director
> would come with a little Chrysler Neon sitting inside it ;)
>
> Karina
>
>
>
> > -----Original Message-----
> > From: Danny Kodicek [mailto:[EMAIL PROTECTED]
> > Sent: 19 March 2007 09:39
> > To: [EMAIL PROTECTED]; flashcoders@chattyfig.figleaf.com
> > Subject: RE: [Flashcoders] Super and this
> >
> >  > Just to make your life simpler.
> > > You do not instantiate a class; you instantiate an
> > > instance(object)  of a class.
> >
> > Isn't that what 'instantiate' means? By 'instantiate' I mean
> > 'make an instance of'.
> >
> > Danny
> >
> > _______________________________________________
> > 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
> >
>
> _______________________________________________
> 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
>
_______________________________________________
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

_______________________________________________
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

Reply via email to