How to define my AppDelegate as instance variable of a class it instanciates ?

Hi

I have got a class IntroMenu defined like this:

IntroMenu.h

class  IntroMenu : public cocos2d::CCLayerColor
{
public:
    AppDelegate* _app;
    //etc...
}

IntroMenu.m

CCScene* IntroMenu::scene()
{
    CCScene *scene = CCScene::node();
    IntroMenu *layer = IntroMenu::node();
    scene->addChild(layer);
    return scene;
}

When I instanciate IntroMenu from my AppDelegate, I proceed like this in AppDelegate:

 introScene = IntroMenu::scene();
 ((IntroMenu*)introScene)->_app = this;

app is a public variable of IntroMenu.
The problem is that
app is a null pointer when I want to use it later in other methods of AppDelegate.

How to instanciate properly IntroMenu and its variable _app ?

Thanks

Yes, in some platform, it is a temporary variable, it is designed for call Application::applicationDidFinishLaunching().

Thanks Minggo but exceptionally you didn’t answer my question :wink: (ok, was probably not very clear…)

So, what I finally did to be able to access and use my AppDelegate is the following (in each method where I need to get my delegate (just a few)):

AppDelegate& tempDelegate = (AppDelegate&)CCApplication::sharedApplication();

Not necessary to keep AppDelegate* _app as instance variable.

Hope this will help somebody.