If all I have is an instance of an object, can I call a static method of its class? For fun, let's say I don't know what the name of the class is, only the name of the static method.
Can I do this? How do I do this?
If all I have is an instance of an object, can I call a static method of its class? For fun, let's say I don't know what the name of the class is, only the name of the static method.
Can I do this? How do I do this?
Get the class reference by it's instance.
var className:string = getQualifiedClassName(object); //returns the class name
var classObj:Class = getDefinitionByName(className) as Class; //get a Class object
Also see this - http://stackoverflow.com/questions/1137730/how-to-get-type-of-variable-and-instantiate-it
You can use the Object's constructor property to get a reference to that object's class object, you can then call the static variable from that class object
package{
import flash.display.Sprite;
public class Test extends Sprite{
public function Test(){
var variable : A = new A();
trace((variable as Object).constructor.a);
}
}
}
class A{
static const a : String = "test";
}