Add Admob Native Extensions with Flash CS6


Admob for Adobe Flash CS6 is a tricky process. To add the admobs ads in your Adobe flash based application just put the following code in the main action script.


package {

import flash.display.MovieClip;
import flash.desktop.NativeApplication;
import com.hdi.nativeExtensions.NativeAds;
import com.hdi.nativeExtensions.NativeAdsEvent;
import flash.utils.setTimeout;

//Path to iPhone SDK /Applications/

public class AdMobExample extends MovieClip {
// Admob - id
private var admobId:String = "your-admob-id";
private static const AD_HEIGHT:int = 50;
private var statusBarHeight: int = 0;
private var _adY:int = 0;
public var na : NativeApplication;

public function AdMobExample() {
// constructor code
na = NativeApplication.nativeApplication;
na.addEventListener(Event.EXITING, exit, false, 0, true);
na.addEventListener(Event.DEACTIVATE, deactivate, false, 0, true);
na.addEventListener(Event.ACTIVATE, activate, false, 0, true);
// lock the scale of the app
// so we can manage the screen sizes and
// positioning ourselves
if ( stage ) {
stage.scaleMode = "noScale";
stage.align = "TL";
//statusBarHeight = 20; //in case the status bar is visible
//if you app is full screen the this should be equal to 0
statusBarHeight = 0; // we are developing full screen app
_adY = 480 - statusBarHeight - AD_HEIGHT; //position the ad at the bottom
// call init when ready
if ( loaderInfo ){
loaderInfo.addEventListener( Event.INIT, init, false, 0, true );
} else {
// close the application
public function deactivate(e:Event):void {
// AdMob
// end AdMob
public function exit(e:Event):void {
// end AdMob
// add a short delay to make sure the app has shut down
//finalize the app.
private function finalExit():void
// AdMob Methods
public function showAd():void {
// add an event listener so we know when an ad is being displayed
NativeAds.dispatcher.addEventListener(NativeAdsEvent.AD_RECEIVED, onAdReceived);
// call showAd and pass in the size and position of the ad
NativeAds.showAd(0, _adY, 480, AD_HEIGHT);
public function hideAd():void {
// remove the ad from view
public function onAdReceived(e:NativeAdsEvent = null):void {
//Anything behind the ad will be hidden, update your layout to handle this edge case.
trace("update ui's size and position");
// end AdMob Methods
private function init(e:Event):void {
// ADMOB - initialize here
//NativeAds.setAdMode(true);//put the ads in real mode
//initialize the ad banner with size compatible for phones, it's applicable to iOS only
NativeAds.initAd(0, _adY, 320, AD_HEIGHT);
// show ad
private function activate(e:Event):void {
trace("App was activated");



Add Admob Native Extensions with Flash CS6 Add Admob Native Extensions with Flash CS6 Reviewed by Admin on 1:20 AM Rating: 5

No comments:

Powered by Blogger.