Cocosbuilder CCControlButton code connection trouble with onResolveCCBCCControlSelector?

Cocosbuilder CCControlButton code connection trouble with onResolveCCBCCControlSelector?
0.0 0


Hi peoples!

I’m satisfied to say I searched for an answer up and down google and the forum.

>I’m using Xcode 4.6
>I’m using Cocos2dx 2.0.4 and cocosbuilder 2.1
>I’m developing for iOS for the iPhone 4 and 5

edit 2
>So clearly the problem I’ve found is that the code inside of “onResolveCCBCCMenuItemSelector” and “onResolveCCBCCControlSelector” is never executed. Nothing I can find says where these functions are supposed to be called. I understand what the CCString selector name parameter/argument, but not the CCObject one.

Any help would be greatly appreciated! Thank you!

So, I managed to get my ccbi file loaded and displayed (is contains only a CCLayer with a CCControlButton inside). CCLayer has a custom class HelloCocosBuilder. CCControlButton has selector: pressedNewGameButton and target’s owner. (no idea what these mean!)

I’ve been following:…

…to get my code hooked up to my button.


bool AppDelegate::applicationDidFinishLaunching()
// initialize director
CCDirector * pDirector = CCDirector::sharedDirector();

// turn on display FPS

// set FPS. the default value is 1.0/60 if you don't call this
 pDirector->setAnimationInterval(1.0 / 60);

 // create and register node loader library
 cocos2d::extension::CCNodeLoaderLibrary* nodeLoader;
 nodeLoader = cocos2d::extension::CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
 nodeLoader->registerCCNodeLoader("HelloCocosBuilder", HelloCocosBuilderLoader::loader());

 // create ccbreader with the default node loaderLibrary
 cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(nodeLoader);

 // load the main node from the ccbi file
 CCNode * node = ccbReader->readNodeGraphFromFile("MainMenuCCB.ccbi");

 // create a scene. it's an autorelease object
 CCScene * pScene = HelloWorld::scene();

 // add the ccbi node to the scene
 if(node != NULL) {

 // release the CCBReader instance since we don't need it anymore

 // run the scene

 return true;


#ifndef __HELLO_WORLD_H__
#define __HELLO_WORLD_H__

// When you import this file, you import all the cocos2d classes
#include "cocos2d.h"
#include "Box2D.h"

class PhysicsSprite : public cocos2d::CCSprite
    void setPhysicsBody(b2Body * body);
    virtual bool isDirty(void);
    virtual cocos2d::CCAffineTransform nodeToParentTransform(void);
    b2Body* m_pBody;    // strong ref

class HelloWorld : public cocos2d::CCLayer {

    // returns a Scene that contains the HelloWorld as the only child
    static cocos2d::CCScene* scene();

    void initPhysics();
    // adds a new sprite at a given coordinate
    void addNewSpriteAtPosition(cocos2d::CCPoint p);

    virtual void draw();
    virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
    void update(float dt);

    b2World* world;
    cocos2d::CCTexture2D* m_pSpriteTexture; // weak ref

#endif // __HELLO_WORLD_H__


 CCScene* HelloWorld::scene()
 // 'scene' is an autorelease object
 CCScene *scene = CCScene::create();

 // add layer as a child to scene
 CCLayer* layer = new HelloWorld();

 return scene;


#include "CCLayer.h"
#include "CCObject.h"
#include "CCControlExtensions.h"
#include "CCBReader.h"
#include "CCLayerLoader.h"
#include "CCBSelectorResolver.h"

class HelloCocosBuilder : public cocos2d::CCLayer, public cocos2d::extension::CCBSelectorResolver {
    //virtual bool init();

    virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, cocos2d::CCString * pSelectorName);
    virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName);

    void pressedNewGameButton(CCObject *pSender, cocos2d::extension::CCControlEvent pCCControlEvent);

    //void pressedContinueButton(CCObject *pSender, cocos2d::extension::CCControlEvent pCCControlEvent);


class HelloCocosBuilderLoader : public cocos2d::extension::CCLayerLoader {
    CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(HelloCocosBuilderLoader, loader);



 SEL_MenuHandler HelloCocosBuilder::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName)
 //CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "pressedContinueButton", HelloCocosBuilder::pressedContinueButton);

 return NULL;

 SEL_CCControlHandler HelloCocosBuilder::onResolveCCBCCControlSelector(cocos2d::CCObject *pTarget, cocos2d::CCString*pSelectorName) {

 CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "pressedNewGameButton", HelloCocosBuilder::pressedNewGameButton);

 return NULL;

 void HelloCocosBuilder::pressedNewGameButton(cocos2d::CCObject *pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {

 CCLOG("Pressed new game button.");

I create a scene in the appdelegate and add the node as a child there before running the scene.
I see “Cocos2d: Unexpected NULL target for selector.” in my log after successfully building. (again, I don’t no what selectors are, or selector resolvers)

I feel like I’m just missing a step somewhere.

So, are cccontrols treated differently from menuitems? Are they just not used anymore or something, uh, deprecated? I can click my button, but the CCLOG (“You pressed the button!”) isn’t executing.

Thank you very much for any help you can offer!


make sure your
class HelloCocosBuilder : public cocos2d::extension::CCBSelectorResolver


Thank you for the reply!

Yes, my builder class extends CCBSelectorResolver. I think if that was missing I’d get a compile error. My project builds and runs just fine; I just know that the code isn’t executing when the cccontrolbutton is pressed.

I edited in my header files into the first post; forgot to do that to begin with.


Well that was rough.

Turns out I needed my target in the CCB file for my cccontrolbutton needed to be set to “Document Root” instead of “Owner”.

Also, deleting Derived Data from the Organizer window in Xcode for a clean build is damn important.


Well that was rough.

Turns out I needed my target in the CCB file for my cccontrolbutton needed to be set to “Document Root” instead of “Owner”.

Also, deleting Derived Data from the Organizer window in Xcode for a clean build is damn important.


I met exactly this problem too, but I don’t want to make my document root a custom class……
what can I do?

The onResolveCCBCCMenuItemSelector and onResolveCCBCCControlSelector are never called.
Only onResolveCCBCCCallFuncSelector is working.