0

I understand that a CCMenuItem has a CCObject* rec and a SEL_MenuHandler selector and that it will call them when selected but I'd like to know if, given just those two variables, I can manually call them myself and, if so, how?

I'm aware of CCMenuItem's activate() method, but I'm trying to call it without creating the CCMenuItem.

Josh Paradroid
  • 1,172
  • 18
  • 45

2 Answers2

1
this->yourFunctionName(NULL);

or

rec->*selector(NULL); 

or

rec->*selector(rec); ?

not quite sure.

m.ding
  • 3,172
  • 19
  • 27
  • Which function is that? I only have the `rec` and the `selector`. Can I get this `yourFunctionName` out of either of them? – Josh Paradroid Nov 05 '12 at 09:46
  • @JoshParadroid when you create the menuItem, what did you put into the mene_selector(YOURCLASSNAME::YOURFUNCTIONNAME)? – m.ding Nov 05 '12 at 22:03
  • I think this is irrelevant. My question is that if, _given just those two variables_ can I manually call them? The menuItem is created elsewhere. I can change my code to take in a menuItem or a function pointer instead if I have to. I'm just wondering if I need to and, if I don't need to, how I can call the selector? – Josh Paradroid Nov 06 '12 at 15:58
  • @JoshParadroid if you check what `menu_selector()` is is doing, actually it is a fucntion Pointer of CCObject::*funtionpointer(CCObject* pObject); you can try `rec->*selector(NULL);` – m.ding Nov 06 '12 at 22:05
  • That won't compile and gives the error `Called object type 'SEL_MenuHandler' (aka 'void (cocos2d::CCObject::*)(cocos2d::CCObject *)') is not a function or function pointer` – Josh Paradroid Nov 08 '12 at 17:04
  • @JoshParadroid that is wield, what did you set to `selector`, or what is selector = ? when you initialise this variable?, because in CCMenuItem::activate(), this is the way to use it, the original code is `(m_pListener->*m_pfnSelector)(this);` where `m_pListener` is an CCObject* and `m_pfnSelector` is an SEL_MenuHandler. – m.ding Nov 09 '12 at 00:30
  • @JoshParadroid together with my last comment, but `m_pfnSelecter` must be valid, which means it must pointing to a function which takes an CCObject* as argument. that is why I asked you at the beginning. you have to set the `selector = menu_selecter(YOURCLASS::YOURFUNC);` if your `selector` is SEL_MenuHandler, YOURFUNC must takes an CCObject* as input. – m.ding Nov 09 '12 at 00:38
  • Thanks for the help, but sadly lack of time prevents me from looking into this further. As a work around, I'm creating a `CCMenuItem` with these parameters and calling activate on it. – Josh Paradroid Nov 15 '12 at 16:03
0

Have you tried:

[rec performSelector:selector];
CodeSmile
  • 64,284
  • 20
  • 132
  • 217