I assume this is AS3 in Flash AS3 preview?

I tried your example code and it worked as expected, even when I
instantiated Subclass by a variable reference to the class. I have a
feeling you have made some mistake in your code... if not, could you
send a complete example, that we can just paste into a file and run?

Peter

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()

}

Thanks

matt

_______________________________________________
[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

Reply via email to