CCMenu getChildByTag does not work

CCMenu getChildByTag does not work
0.0 0


I tried to use CCMenu and addChild to add CCMenuItem, when I call CCMenu getChildByTag. I got message says: “getActionByTag: Target not found”.

Any idea what is wrong.

The sample code is:

CCMenuItemImage speaker = CCMenuItemImage::itemFromNormalImage);
CCMenu menu = CCMenu::menuWithItem;
item = menu~~>getChildByTag;*****
here does not work.

Any idea what I did wrong here?




Tag is a member of CCNode, you can check if speaker->m_nTag equals to 8 after setting it.
And then, check whether speaker is really a child of menu.


speaker~~>m_nTag is a protected member. But I will be able to get the tag by calling speaker~~>getTag(), the result is 8.

only when I call menu->getChildbyTag(8), I did not get the speaker back.


CCMenu::menuWithItem(speaker) doesn’t add speaker as a child of CCMenu, it justs add speaker to its array.
It meas that speaker is not a child of menu.
So you can not use getChildByTag to find it.


Then how can we get the CCMenuItem object if we only know the tag?


I can get the CCMenuItem by menu->getChildByTag(tag) without problem.