On 6/29/07, Andrew Sinning <[EMAIL PROTECTED]> wrote:
How do you get a super-class instance to call an over-riding method in a sub-class? I'm using AS2.
Hackish, but you could do SubClass.prototype.myMethod.call( this, arg1, arg2...); Anyway, you don't need this, because I think what you're trying to achieve is happening automatically already. Say you have Foo extends Bar. Bar has the 'load' method. Both have a 'parse' method, where Bar's does some general stuff and Foo's some special, additional stuff: class Bar { ... public function load () : Void { ... } public function parse ( data : XML ) : Void { ... } } class Foo extends Bar { ... public function parse ( data : XML ) : Void { super.parse( data ); ... } } So, you do 'var foo = new Foo()', and then 'foo.load()', I think this is what you mean by "The call to start loading the data begins in the super-class". You wrote it in the super class, but note that it's all happening in the scope of 'foo', an instance of Foo. There isn't really a difference between what is in the super class and what is in the main class -- as long as it's not overridden, it's as if the sub class would have the exact same code (with the exception of static properties). When 'parse' is called on 'foo', it will be Foo's 'parse', no matter if the piece of code is written in your Foo, Bar, or any other ancestor class. This is all being done automatically, there is nothing you have to do for that to happen. However, calling the super class' method even though it's overridden is something you have to do explicitly. This is done by prefixing 'super', like in the example above, in Foo's 'parse' method. There are a few on the FlashNewbies list who are also just getting into OOP with AS2. You might want to join that list, also on ChattyFig. They'll be running into the same problems, and questions get answered in more detail there. HTH, Mark
I'm parsing data into an object. The parser method is generalized, so it should be in the super-class, I think... But there are exceptions in the sub-classes. The call to start loading the data begins in the super-class, but some of the sub-classes might have there own over-riding parser methods. Furthermore, any input values not caught by the parsers of the sub-classes need to get passed back up to the super-class. Does this make sense? I did this kind of thing all the time with lingo, but since I've been reading Moock I'm trying to write better OOP. This has got to be a pretty common thing to run across. Thanks! _______________________________________________ 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