Forum › Kiwi.js Game Engine › Group or State getChildren()
-
So this might be more of a general typescript question but anyway I have a Kiwi.Group of objects and which are a custom class that derives from a Kiwi.GameObjects.Sprite.
So the question is if I want to iterate over them I would use something like the following code
var children: Kiwi.IChild[] = this.getAllChildren();
for (var obj in children )
{
obj.CustomClassFunction();
}Now how do I cast from an IChild to my own custom type? I don’t really want to keep a separate list of objects.
Thanks in advance
April 28, 2015 at 12:34 pm #5431One way is before calling the CustomClassFunction you can tell typescript to “treat” obj as an instance of your CustomClass.
var children: Kiwi.IChild[] = this.getAllChildren();
for( var obj in children )
{
(obj).CustomClassFunction();
}
Another can be to change the type of your list to any. You may not have code completion if you do it that way though.
var children: any = this.getAllChildren();
for( var obj in children )
{
obj.CustomClassFunction();
}
Hope that helps!
April 28, 2015 at 8:34 pm #5432
You must be logged in to reply to this topic.