Home

Game Distribution edited this page Jan 29, 2016 · 10 revisions
Clone this wiki locally

Importing SWC

Click import SWC file

Include Code

Initialize the API

Methods

/**
 * Logger initializes the API.  You must create GDApi first before doing anything else. 
 * It is a singleton class.
 * @param   gID     Your game id from GameDistribution
 * @param   guid        Your game guid from GameDistribution
 * @param   root        Should be root to detect the page
 */     
    GDLogger({gid:gID,userid : guid, root : DisplayObject});

/**
* API sends how many times 'Play Button' is clicked. If you invoke 'PlayGame' many times, 
 * it increases 'PlayGame' counter and sends this counter value. 
*/              
PlayGame();

/**
 * API sends how many times 'CustomLog' that is called related to given by _key name. 
 * If you invoke 'CustomLog' many times, it increases 'CustomLog' counter and 
 * sends this counter value. 
 */     
 * @param   _key        Your custom key it should be maximum 10 chars
 */     
CustomLog(_key:String);

/**
 * API reshows banner. For example you need to show banner 
 * before starting a level, you can call ShowBanner({_key:"level1"}), 
 * if you need to show sample banner for ONLY test purpose, 
 * call ShowBanner({test:true})
 */     
 * @param   _key        It should be maximum 10 chars
 */     
ShowBanner({_key:"keyword"});

/**
 * It closes Banner
 */
CloseBanner();

/**
 * Sets the API to use SSL-only for all communication
 */
SetSSL();

Properties

/**
 * Set Blocked Screen Text.
 */
BlockText = "Please visit our site www.GameDistribution.com";

Events

/**
 * Triggered by block links checking state
 */
GDEvent.SITE_NOTALLOWED

/**
 * Triggered by your game localy running state
 */
GDEvent.RUNNING_LOCAL

/**
 * Banner is started
 */
GDEvent.BANNER_STARTED

/**
 * Banner is recieved from the server
 */
GDEvent.BANNER_RECEIVED

/**
 * Banner is closed
 */
GDEvent.BANNER_CLOSED

/**
 * API is not loaded
 */
GDEvent.API_NOTLOADED

Examples

/**
 * Events Example
 */

// Game constructor
public function Main() 
{           
    // GD Analytics         
    var GdAPI = new GDLogger({gid:"1e913e1b06ead0b66e30b6867bf63549",userid : "82b343c2-7535-41f8-a620-c518e96de8f6-s1", root : root});
    GdAPI.BlockText = "Please visit our site <a href='www.gamedistribution.com'>www.gamedistribution.com</a>";              
    GdAPI.addEventListener(GDEvent.BANNER_CLOSED,onBannerClosed);
    GdAPI.addEventListener(GDEvent.BANNER_STARTED,onBannerStarted);
    GdAPI.addEventListener(GDEvent.BANNER_RECEIVED,onBannerReceived);
    GdAPI.addEventListener(GDEvent.SITE_NOTALLOWED,onAllowedLinks);
    GdAPI.addEventListener(GDEvent.RUNNING_LOCAL,onRunningLocal);
    GdAPI.addEventListener(GDEvent.API_NOTLOADED,onApiNotLoaded);
    GdAPI.EnabledDebug = true;  

    // Game Init. 
    GameInit();
}

private function onApiNotLoaded(e:Event):void
{
    GameResume();   // When API is not loaded, resume game.     
}

private function onBannerClosed(e:Event):void
{
    GameResume();   // You can resume your game     
}

private function onBannerStarted(e:Event):void
{
    GamePause();    // You can stop or pause your game      
}

private function onBannerReceived(e:GDEvent):void  
{  
    Log("Banner received...\nDimensions:" + e.data.dimensions+ "\nTime:"+e.data.remainingTime+ "\nisInterstitial:"+e.data.isInterstitial);

} 

private function onAllowedLinks(e:Event):void
{
    GameStop(); // If links are not blocked by web site, you can stop or pause your game        
}

private function onRunningLocal(e:Event):void
{
    trace("Game is locally running..");         
}

Example for showing banner between two levels

/**
 * Banner Example
 * It fires the banner after timeout period. You cannot invoke method every calling of function.
 */

private function ShowLevelBanner(level:int):void
{
    GdAPI.ShowBanner({_key:"level"+level});     
}