Help with implementing FGL ads?


(Ortson) #1

I just created a game for the miniLD and I wanted to try to implement the FGL ads, just for fun not too make any big money. I tryed to implemet them using this code for my Main class(I got most of it from emanuele feronato):

 package 
{
    import net.flashpunk.Engine;
    import net.flashpunk.FP;
    import A;
    import flash.display.StageQuality;
    import flash.events.Event;
 
    public class Main extends Engine
    {
        // variable declaration
        private var ads:FGLAds;
        
        public function Main()
        {
            super(640, 480, 60, false);
            // FGL-56 is my game ID
            ads=new FGLAds(stage,"FGL-xxxxxxx");
            // waiting for the api to be ready to call showStartupAd
            ads.addEventListener(FGLAds.EVT_API_READY, showStartupAd);
            // should it take too long to load, let's skip the ad and call enableGame function
            ads.addEventListener(FGLAds.EVT_AD_LOADING_ERROR, enableGame);
        }
 
        private function showStartupAd(e:Event):void {
            // showing ad popup
            ads.showAdPopup();
            // waiting for the player to close the popup
            ads.addEventListener(FGLAds.EVT_AD_CLOSED, enableGame);
        }
 
        private function enableGame(e:Event):void {
            // removing listeners
            ads.removeEventListener(FGLAds.EVT_AD_CLOSED, enableGame);
            ads.removeEventListener(FGLAds.EVT_AD_LOADING_ERROR, enableGame);
            // start the game
            init();
        }
        
        private function init():void{
            // here starts the game, which calls showGameOver function when the game is over
            FP.world = new Start();
        }
        
    }
    
}

The ads shows up when I run it from within flashdevelope but then when I start it in a browser the game does not start at all. Do you have any suggestions?

*Fixed code formationg


(Justin Wolf) #2

I would imagine it has something to do with this line. ‘xxxxxxx’ is likely a unique code FGL gives you that represents your game. I’ve never used FGLAds, but that’s my first guess. Second guess would be your AdBlock (if you have it enabled) is blocking the ads.


(Ortson) #3

The adblock thing did it! Do you have any recomendations on how to start the game if adblocks is activated so it dosent freeze? The xxxxxx thing isnt there I just replaced it in case of it is supposed to be private or something.


(Jacob Albano) #4

You could create a timer with an event listener that fires off after a certain amount of time has passed. If the game hasn’t started by then (because of adblock), launch it anyway, or display a message that recommends the player disable adblock to get it to run.


(billy2000) #5

That’s exactly what i did with the ads on my last game :smiley: