0

I try many ways to get all children in a cc.Layer In my Layer, i have 2 childrens. I using the following code to get all children and runAction FadeOut for all children in my Layer

for (var child in this._children){
        child.runAction(
            cc.FadeOut.create(interval)
        );
}

In this above code. Type of this 'child' is cc.Node. But the value of this is 'index of' this chilren (ex, 0 or 1). So, when i execute 'runAction', i got an error: "Object 0 has no method 'runAction'"

In try to get child by tag as the following to compare 2 variable

var child0 = this.getChildByTag(0);

The result also cc.Node but value totally different from previous code. And i totally execute 'runAction' method with no error

So, how could i get ALL CHILDREN and receive each children like "getChildByTag" method.

Thanks in advance

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Jonny Vu
  • 1,420
  • 2
  • 13
  • 32

1 Answers1

0

I resolved my problem with a simple way. I discovered that for loop has a problem. Instead of using for-in i using the following:

 var childNode = this._children;
    for (var i=0; i<childNode.length; i++){
        var child = childNode[i];
        child.runAction(
            cc.FadeOut.create(interval),
            cc.CallFunc.create(this.removeFromParent,this,true)
        );
 }

It completely right!

Jonny Vu
  • 1,420
  • 2
  • 13
  • 32