Notice that this is just an extension of the work made by Terry Paton (@terrypaton1) in his tutorial AdMob adverts in AIR for Android applications. Check it for an introduction.
I ‘ve made a simple class using Terry’s code and adding some extra functions.
You can download it here: AdMob.as
Basically all you have to do is create an instance of AdMob class passing the URL where your adMob html is placed and an stage reference.
var ad: AdMob =new AdMob("http://yourAdMobURL.com/",stage);
you can also use updateAd() function to change the adMob html or refresh the previous url.
ad.updateAd("optionalNewURL");
You can download an html adMob template here. Just change the publisher ID and the colors.
How to make the ads are always displayed?
When the ad is already working, there is a big deal because sometimes the ad is showed and sometimes not.
I was dealing with this for a while. I tested the html page where the ad is placed with an iPod Touch and the ads was displayed all the time. In Android devices the ad was displayed only sometimes but when runs in one, runs with the rest. If the adMob was in test mode the ad was displayed without problems.
So, what is the problem? It is quite simple. There are no enough ads.
If you are a publisher you can choose where you want your ad be displayed. You can choose between iPhone apps, iPhone sites, Android apps and Android sites. Seems that there are not enough publishers interested in sites visited with Android phones.
The best solution I found to this problem is to create a “House ad” in the adMob “Sites and Apps” menu.
This is an ad that we can link to where we want and will be displayed when there is no “normal ads” to display.
Once you create it, go to “Sites and Ads” page , click edit on the “House ads” column. Turn “House ads” on, and save settings.

Gracias Xavi, llevaba tiempo con ganas de probar esto y entre tú y Terry me imagino que me habéis salvado un montón de tiempo de pruebas
Gracias Jorge! Cuentame si te funciona!
Xavi, ¡funcionando perfectamente!
Moltes gràcies (está bien así, ¿no?
)
Ha ha! Sí. Genial!
hi Xavi,
thank you… it’s great!
The only issue I have is that my graphic houseAd are showing on my android device with scroll.
Any ideas how to solve this?
Vivo
Hi vivo!
I’m travelling right now. I’ll check it in a couple of days.
enjoy!
Hi Vivo! Sorry for the delay…
I’m not avaiable to check out it directly with my Android because it has broken…
Anyway I think that probably is because the StageWebView is smaller than your HTML. Try to make it bigger, and be sure the HTML don’t have extra margins.
Does it run with normal ads? or is just houseAds?
hey, I actually came up with a solution myself using a stagewebview which i bet is what youre doing, but before i turn the test mode off and put my app on the market, i was trying to go around the web and find other people that have done this and make sure they never got their admob accounts suspended. I asked admob here
https://groups.google.com/forum/#!topic/google-admob-ads-sdk/85WFd2uOggQ
but havent gotten any replies. I read somewhere else someone saying that their admob account got suspended for click fraud. (maybe their situation was different because they were testing without test on or something) I’m wondering if how what we’re doing with the prevent default then opening it up the destination url in the native browser makes it look like a bad click. Have you been doing it an an application that gets a lot of traffic/clicks?
Brybam,
I haven’t publish any app with ads yet. I know @terrypaton1 gets banned but don’t know why. Please, shared it if you get the answer I’m very interested on it.
try and bump up my thread that i posted over at the admob forum
https://groups.google.com/forum/#!topic/google-admob-ads-sdk/85WFd2uOggQ
They seem to be pretty active on answering questions, but they completely ignored mine. I hope more flash/flex developers start asking for a native sdk or at least about this workaround implementation
Brybam, there is an unofficial port of AdWhril.
http://code.google.com/p/adwhirl-flash-sdk/
You should be able to run adMob ads without using webStageView
I get no succes. I just got running the House ads.
Oh cool! I dont have an adwhirl account, but i will definitely look into setting it up. From the looks of that link there is barely any suport or any documentation or any information from the person who made it. But i’m still going to give it a shot and see how it works, it might be the best thing for people making flex apps for android now
Brybam, I tried to contact to the developer but he didn’t respond. I didn’t find any kind of documentation.
Start with the invoker.as class. I belive you will also need to download some extra classes that are missing.
Let me know if you get succes
Just to let you know, I published an android app with ads using the AdMob walk-around you showed here and it seems to be working just fine… (i didn’t got banned or nothing)
I wonder if it would work on Adobe AIR apps for IOS?
(knowing Apple, probably not)
Hi mates, I have followed the link
http://help.adobe.com/en_US/as3/dev/WS901d38e593cd1bac3ef1d28412ac57b094b-8000.html#WS901d38e593cd1bac-7b2e067c12e72dd6960-8000
and I managed to have it working
However:
1) I’m not able to create a “House Ad” linked to my test advertize app maybe because of its type (that is “smartphone web”)
2) I have never seen the ad changing. After how many seconds/minutes does it happens?
Do you have any suggestion?
Thanks in advance
Baron Karza,
I believe it dosen’t matter if it is an “smartphone we”. What is exacly the problem?
I do not remember well now bu I think you can change the time on your adMob account. Anyway what you can do is to call the function
“ad.updateAd(“optionalNewURL”);”
to reload again the ad (and it probably will load with anothe one).
im confused, i copied AdMob.as and added it to my project as a .as file. My admob.html is on server. where do i add
var ad: AdMob =new AdMob(“http://mydomain/admob.html”,Stage);
i have tried multiple places and cant get it to work, please help. Should this be on the .mxml page i want to display ads, am i calling the class incorrectly
Chris,
You have to pass “stage” and not “Stage”.
Do you recive any kind of error?
When i put stage in the .as file it says
access of undefined property stage
when i put stage or Stage in .mxml (app page)
it says
1046: Type was not found or was not a compile-time constant: AdMob.
im sure im putting stuff in the wrong place, please can you describe where each part has to go.ie where does AdMob.as go, in a seperate .as file?. where does
var ad: AdMob =new AdMob(“http://mydomain/admob.html”,Stage); go, where you want the add?
In MXML I’m not sure how it works.
In an AS3 project you can acces to the stage proprety in the main class.
So, if you put the code on the main class it should work.
After a lot of trouble (account canned on ADMOB ) and research, I have gotten Ads to work in all my Android Apps. This will work on a lot of AD networks, but most will ban you click fraud. Only one network allows this method and they provide support for it too.
I have over 100 games apps. with this method implemented and working. Here is a link to one of them for you to see how it will look in game. I am using multiple ads in this to force the user to click and make me some money: https://market.android.com/details?id=air.GraffitiCityMarketFree&feature=search_result
Does LeadBolt offer HTML integration for banner ads?
LeadBolt does allow banner ads to be integrated into your app using HTML, rather than using our SDK. To create a HTML banner ad after adding an app to the LeadBolt portal, simply click “Add Ad” and select “App Banner (HTML)” from the drop down box. The HTML snippet can then be added directly into your app’s HTML framework.
So far my eCPM is $6.15
I have created this guide to show my appreciation:
Publisher Code:
STEP I:
Get an Account: http://leadboltapps.com/web/publishers/signup.php?ref=10022842
STEP II:
Click on the “APPS” tab and “Create New APP” to create an AD. Remember to change content unlocker to HTML Banner. While in the process.
STEP III:
Get the HTML AD Code and keep it safe. That is all we need from the site. How simple was that?
AD HTML FILE:
Create an HTML File and Load it to your site. Remember to replace your HTML Code from above step with where I have put: ****ENTER HTML AD CODE HERE****
Untitled Document
body,td,th {
color: #FFF;
}
body {
background-color: #000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
text-align: center;
position: relative;
}
****ENTER HTML AD CODE HERE****
Action Script Code:
STEP I:
Credit: I found this on another site and would like to give credit to the author of pixelpaton.com
The only change you need to make is to enter your website html url where you have placed the AD HTML FILE in the space where I have put : “****ENTER COMPLETE HTML URL HERE****”. Where ever you want the AD, place the following code:
// imports
import flash.events.Event;
import flash.events.LocationChangeEvent;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;
// setup variables
var _stageWebView:StageWebView;
var myAdvertURL:String = “****ENTER COMPLETE HTML URL HERE****”;
//
{
// check that _stageWebView doersn’t exist
if (! _stageWebView) {
_stageWebView = new StageWebView () ;
// set the size of the html ‘window’
_stageWebView.viewPort = new Rectangle(0,0, 800, 100);
// add a listener for when the content of the StageWebView changes
_stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onLocationChange);
// start loading the URL;
_stageWebView.loadURL(myAdvertURL);
}
// show the ad by setting it’s stage property;
_stageWebView.stage = stage;
}
function toggleAd(event:MouseEvent):void {
trace(“toggling advert”,_stageWebView);
// check that StageWebView instance exists
if (_stageWebView) {
trace(“_stageWebView.stage:”+_stageWebView.stage);
if (_stageWebView.stage == null) {
//show the ad by setting the stage parameter
_stageWebView.stage = stage;
} else {
// hide the ad by nulling the stage parameter
_stageWebView.stage = null;
}
} else {
// ad StageWebView doesn’t exist – show create it
}
}
function destroyAd(event:MouseEvent):void {
// check that the instace of StageWebView exists
if (_stageWebView) {
trace(“removing advert”);
// destroys the ad
_stageWebView.stage = null;
_stageWebView = null;
}
}
function onLocationChange(event:LocationChangeEvent):void {
// check that it’s not our ad URL loading
if (_stageWebView.location != myAdvertURL) {
// destroy the ad as the user has kindly clicked on my ad
destroyAd(null);
// Launch a normal browser window with the captured URL;
navigateToURL( new URLRequest( event.location ) );
}
}
// setup button listeners
Hope this works and helps you. If you have questions, let me know. Enjoy.
I have tried doing everything, I get the ad to display when you press a button but not by itself. How do you do this? does anyone have a source .fla?
I’ve just released a full AIR 3 native extension that does this for you – no stagewebview, actual native AdMob ads. Blog post here: http://www.milkmangames.com/blog/2011/11/10/announcing-native-android-admob-support-for-adobe-air/
Hey Alex!
That’s awsome!
But will be more awsome if you post it for free
Hola Xavi, gracias por la clase, quiero empezar a hacer app ya que me gusta desarrollar con as3. Ya que veo que vas unos cuantos pasos por delante de mi en esto de las app
me preguntaba si sabes algo acerca de in-app en ios desde app desarrolladas en as3 ¿conoces esto ? http://www.milkmangames.com/blog/tools/
un saludo
Hey Cesar!
Perdona la demora. He estado algo desconectado de la escena ultimamente. me sabe mal pero no te puedo ayudar demasiado. Sin embargo gracias a las ultimas actualizaciones de Adobe deberia ser posible mediante las extensiones nativas.
Conozco el enlace, djaron un comentario justo antes que tu.