B. EventHandler

EventHandler is for getting return values from async invocations or getting events related to interstitial popup view.

TnkAdEventHandler is shown as below. You can see a common parameter named handleId, which is assigned at each async calls and returned to the corresponding callbacks of TnkAdEventHandler object. You can use handleId values to identify your async calls.




#define TNK_CLOSE_EXIT 2

#define TNK_FAIL_NO_AD -1

#define TNK_FAIL_NO_IMAGE -2



#define TNK_FAIL_SYSTEM -9

#define TNK_PUB_STAT_YES 1

class TnkAdEventHandler {


virtual void onClose(int handleId, int type) {}

virtual void onFailure(int handleId, int errCode) {}

virtual void onLoad(int handleId) {}

virtual void onShow(int handleId) {}

virtual void onReturnQueryPoint(int handleId, int curPoint) {}

virtual void onReturnPurchaseItem(int handlerId, long curPoint, long seqId) {}

virtual void onReturnQueryPublishState(int handleId, int pubState) {}

virtual ~TnkAdEventHandler() {}


Follow steps below to use TnkAdEventHander.
  1. Define a class as a subclass of TnkAdEventHandler or use a pre-existing class by adding inheritance of TnkAdEventHandler.
  2. Implement methods relevant your logic. (You don't have to write down every method in TnkAdEventHandler.)
  3. Instantiate a object of your TnkAdEventHandler class and assign it to TnkAdPlugin by invoking TnkAdPlugin.setEventHandler() method.
In the sample code below, pre-existing HelloWorld class is used for TnkAdEventHandler.

TnkAdEventHandler Sample code

// HelloWorldScene.h

class HelloWorld : public cocos2d::CCLayer, public TnkAdEventHandler



    //  ...


    // add TnkAdEventHandler methods

    virtual void onReturnPurchaseItem(int handlerId, long curPoint, long seqId);

    virtual void onReturnQueryPublishState(int handlerId, int pubState);

    virtual void onReturnQueryPoint(int handlerId, int curPoint);


// HelloWorldScene.cpp

bool HelloWorld::init()


    // ...

    // Set EventHandler object 


    return true;


void HelloWorld::onReturnQueryPoint(int handlerId, int curPoint) {

    char buf[100];

    sprintf(buf, "onReturnQueryPoint : curPoint = %d", curPoint);

CCMessageBox(buf, "Alert");


void HelloWorld::onReturnPurchaseItem(int handlerId, long curPoint, long seqId) {

    char buf[100];

    sprintf(buf, "onReturnPurchaseItem : curPoint = %ld, seqId = %ld", curPoint, seqId);

CCMessageBox(buf, "Alert");


void HelloWorld::onReturnQueryPublishState(int handlerId, int pubState) {

    char buf[100];

    sprintf(buf, "onReturnQueryPublishState : state = %d", pubState);

CCMessageBox(buf, "Alert");