Whoops! I didn't actually run this test code, just abstracted from my
problem and spat it out.
I guess my buttons are not instantiated like I thought they were.
I'll take another look.
Thanks JC--"override" must be applied to any protected or public
method that is overridden in a subclass, in AS3.
Hi,
running your example shows: subclass init, as it should.
public override function init(){
trace ("subclass init");
}
whats the override keyword doing there?
greetz
JC
On 11/14/06, Matt Garland <[EMAIL PROTECTED]> wrote:
I was hunting a bug when I found this out:
class SuperClass {
public function init() {
trace ("superclass init");
}
}
class SubClass extends SuperClass{
public override function init(){
trace ("subclass init");
}
}
if you create a subclass instances and cast it (or type its variable)
to the superclass, when init is invoked, the superclass init is
called.
var aInstance:SuperClass=new SubClass();
aInstance.init();//"superclass init"
Makes senses, now how about a way around this? I want to make sure
the instance's OWN init() is called.
Here's the context: I'm upcasting in a button factory class, when
SubClass is a variable:
public function ButtonFactory(graphicsFactory:graphicFactory,
buttonClass:Class) {
//the compiler won't let me cast to an unknown class, so
//since I know buttonClass is a descendent of BaseButton, which has
all the relevant graphics-setting methods, I upcast it
//buttonClass-->BaseButton
aButton:BaseButton=new buttonClass()
//the graphics settings methods are in BaseButton, so I'm fine to
build up the graphics
aButton.disabledState=graphicsFactory.makeDisabledState()
//but this calls BaseButton.init(), not buttonClass.init()
aButton.init()
}
_______________________________________________
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