Callback Function | Show Active Tab | Arrow Function | Lamda Function | Functions

Cocos Creator Version - 2.4.7

Intent - Show a golden color border to the active tab. Rest tab shown without the golden border.

What i’m doing is setting active status of the node containing GoldenBorder to false. And then making the active status as true which is being clicked.

The code :-

// nodePool is a array of nodes where i'm pushing all the instantiated prefab.
CloseAllBorder()
{
    for(let i=0; i<nodePool.length; i++)
    {
        this.nodePool[i].getChildByName("GoldenBorder").active = false;
    }
}


// the below script is added in the prefab.
ShowActive()
{
    this.CloseAllBorder();
    this.node.getChildByName("GoldenBorder").active = true;
}

The above code is working well and fine.
What i want is that ShowActive() Function should execute only and only if CloseAllBorder() has executed successfully.

  • If for some reason CloseAllBorder() fails to execute then ShowActive() should throw an error message.
  • Or if there is a delay in execution of CloseAllBorder() function then ShowActive() should wait for CloseAllBorder() to complete its execution.

How can the above mentioned two scenario’s be achieved?

Any leads regarding the query is highly appreciated.