Haxe type casting

Hello All,

may be i’m asking silly question, but i fail to find the answer.

is there a way to cast types something like this:

Image(entity.graphics).centerOrigin();

So in this sample graphics property may contain different types inhereted from some base class, but i need to call method of the specific class.

Sure, i can write it without the cast and compiler will determin everything. But i want completion to work in sublime text. And i do not want to declare variable to use cast keyword.

You can cast in haxe,
the syntax is cast(object, Class),
making your code cast(entity.graphics, Image).centerOrigin();.

See http://haxe.org/manual/expression-cast.html for a slightly more detailed explanation.

3 Likes