About getActionByTag

Hi all.
first, my English might be strange but I hope you do not mind.
I have no idea what is wrong in this problem below.

bool HelloWorld::init(){
    ...
    setAnimation();
    runAnimation();
    ...
}
void HelloWorld::setAnimation(){

    CCSprite* pSprite = CCSprite::create("a.png");
    
    CCAnimation* animation = CCAnimation::create();
    for (int i = 1; i<5; i++) {
        char szName[50] = {0};
        sprintf(szName, "mainCharacterRun%d.png",i); // mainCharacterRun%d.png is filename
        animation->addSpriteFrameWithFileName(szName);
    }
    animation->setDelayPerUnit(0.1);
    animation->setLoops(-1);
    
    CCAnimate* action = CCAnimate::create(animationRun);
    action->setTag(kTagAction);
}
void HelloWorld::runAnimation(){
    CCSprite* pSprite = (CCSprite*)this->getChildByTag(kTagSprite); // kTagSprite is pSprite's tag.
    CCAnimate* action = (CCAnimate*)this->getActionByTag(kTagAction);
    pSprite->runAction(action);
}

and error is Cocos2d: Assert failed: Argument must be non-nil
Assertion failed: (action != __null), function runAction, file /Applications/cocos2d-x-2.2.2/cocos2dx/base_nodes/CCNode.cpp, line 1007.

How to use getActionByTag?
if I do not have to use this, please give me an example. But Tag must be used.

please help me :frowning:

You create the CCAnimate action, and you set a tag, but you never add it to this.

@Ajas Thanks.
But I do not understand well what you are saying.

Can you tell me a little more in details?

when you create action :
CCAnimation* action = CCAnimate::create(animationRun);
action -> setTag(kTagAction);

you did not run the action at once, the action will be released.

if you want to use it , just do it like this when onEnter :
CCAnimation* action = CCAnimate::create(animationRun);
action -> setTag(kTagAction);
action->retain();

finally you have to release it when onExit, using:
action -> release();