Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

E. Managing Interstitial Ads

Hadi Tavakoli edited this page Jun 14, 2018 · 4 revisions

To generate a new Interstitial Ad, you must have initialized the Admob ANE. An interstitial ad, is a fullscreen layer which opens over your whole Air app/game. so it's very important to know how you should use it in your games. make sure to read the best practices for interstitial ads by Google. With interstitial ads, you don't have control over the position nor the dimensions. It's just a fullsreen ad! You should initialize it with loadAd() and then show() it when appropriate.

NOTE: Requesting an ad can be customized. To learn more about the possible properties, read here.

// don't forget to initialize the Admob first
// https://github.com/myflashlab/Admob-ANE/wiki/B.-Initialization-and-Listeners

AdMob.api.addEventListener(AdMobEvents.AD_LOADED, 				onAdLoaded);

AdMob.api.interstitial.init("ca-app-pub-9476398060240162/1457820116");

var adRequest:AdRequest = new AdRequest();
adRequest.testDevices = ["an array of device IDs so you can receive test Ads when developing!"];

/*
If you don't know how you can receive your device's ID, read here for Android:
https://firebase.google.com/docs/admob/android/targeting#test_ads
or here for iOS:
https://firebase.google.com/docs/admob/ios/targeting#test_ads
*/

AdMob.api.interstitial.loadAd(adRequest);

private function onAdLoaded(e:AdMobEvents):void
{
	if (e.adType == AdMob.AD_TYPE_INTERSTITIAL)
	{
		// Your Ad is ready to be shown. show it whenever you like!
		if(AdMob.api.interstitial.isLoaded)
		{
			AdMob.api.interstitial.show();
		}
	}
}