Cocos2d-x can make static pages with Cocos Studio, and when we manipulate the controls in our code, we need to use the API to get the controls to manipulate them. For beginners, getting a control can cause a program to crash with some inexplicable errors, and here's where it's possible to get a control that is NULL.
There are two ways to get a UI control (I know only two of them at this time):
1, through the parent node->getchildbyname ("Control name") layer obtained, this method in obtaining child nodes of child nodes, slightly cumbersome, can be used in the second way.
2, through cocos2d::ui::helper::seekwidgetbyname (the base container, "control name"); getting This method is convenient when getting child nodes of a child node .
The following possibilities are possible (not exhaustive) when getting controls that cause the control address to be NULL:
1. The control name does not match the name of the control in Cocos studio, with particular attention to capitalization.
2. Cocos Studio Publishing resources are not synchronized with the code:
① maybe you edited it in Cocos Studio, but there is no publishing resource that is not available in the code.
② may be that you have published a resource in Cocos Studio but changed the file path on the second change and then published it again, but forgot to change the path in the code, resulting in the get null. (This kind of situation is easy to ignore, I am this kind of situation to toss a day of time hope can help everybody).
About Cocos2d-x getting UI controls to null considerations