Prev | Current Page 859 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

You have to specify the full
path with correct dot syntax if the class you want to resolve is contained in a subpackage. Note the
differences between createInstance() and createEmptyInstance() : The first creates an object
using the new statement and therefore also needs the constructor arguments while the other builds the
instance without invoking the constructor. This can be handy when an object has been serialized or
stored to some media and must be rebuilt without invoking a second initialization.
Another common operation performed by the Type class is to discover the types of the objects.
class TypeSample
{
public static function main()
{
// an array of items of different types
var objs = [
RGB(255, 200, 0),
new Person(???John???),
{ text : ???I am anonymous??? },
White,
10
];
for(ob in objs)
{
switch(Type.typeof(ob))
{
case TClass(cl):
trace(???Instance of ??? + Type.getClassName(cl));
case TEnum(e):
trace(???Enum ??? +
Type.getEnumName(e) + ???.??? +
Type.enumConstructor(ob) +
???(??? + Std.


Pages:
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871