toEnum(t:Dynamic) : Enum Returns an Enum definition if the passed value is
an Enum; returns null otherwise.
typeof(v:Dynamic) : ValueType Returns the type of the passed argument.
ValueType is an enum with the following constructors:
TNull;
TInt;
TFloat;
TBool;
TObject;
TFunction;
TClass( c : Class < Dynamic > );
TEnum( e : Enum );
TUnknown;
With Type, an object can be instantiated using just the class name. This can be done in two ways using
the createInstance() and the createEmptyInstance() .
class Vehicle
{
public static function main()
{
var cl = Type.resolveClass(???Vehicle???);
var v1 : Vehicle = Type.createInstance(cl, [???motorcycle???]);
trace(v1.type); // trace ???motorcycle???
var v2 : Vehicle = Type.createInstance(cl, [null]);
trace(v2.type); // trace ???car???
var v3 : Vehicle = Type.createEmptyInstance(cl);
trace(v3.type); // trace null
}
Chapter 16: haXe Advanced Topics
469
public var type : String;
public function new(?type : String)
{
this.type = if(null == type) ???car??? else type;
}
}
The resolveClass() returns a Class type that is used to identify the class.
Pages:
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870