• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3 How to add adMob to Adobe Flash/Animate?

Participant ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

 

Please help me to figure out how to add adMMob to my Actionscript 3 app. There isn't well-written documentation on how to do it. I only found a youtube video that explains it but still, it was not well and fully described. for the bits and pieces of information that I gathered, I managed to construct the following code, however, it errors. Please help to reconstruct the code so I get it to work.

 

  1. First I got Pozirk's AdMob Air Native Extension from github
  2. I installed the AdMob.swc and the AdMob.ane files in the Advanced ActionScript settings
  3. I created a class file called Main.as which contains the following code:
package 
{	import flash.display.MovieClip;
	import com.pozirk.ads.admob.AdMob;
	import com.pozirk.ads.admob.AdParams;
	import com.pozirk.ads.admob.AdEvent;
	var _admob: AdMob = new AdMob();
	public class Main extends MovieClip
	{
		public function Main()
		{
			//> initialization of AdMob
			_admob.addEventListener(AdEvent.INIT_OK, onEvent);
			_admob.addEventListener(AdEvent.INIT_FAIL, onEvent);
			_admob.addEventListener(AdEvent.BANNER_SHOW_OK, onEvent);
			_admob.addEventListener(AdEvent.BANNER_SHOW_FAIL, onEvent);
			_admob.addEventListener(AdEvent.BANNER_LEFT_APP, onEvent);
			_admob.addEventListener(AdEvent.BANNER_OPENED, onEvent);
			_admob.addEventListener(AdEvent.BANNER_CLOSED, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_SHOW_OK, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_SHOW_FAIL, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_CACHE_OK, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_CACHE_FAIL, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_LEFT_APP, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_OPENED, onEvent);
			_admob.addEventListener(AdEvent.INTERSTITIAL_CLOSED, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_CACHE_FAIL, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_CACHE_OK, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_CLOSED, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_COMPLETED, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_LEFT_APP, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_OPENED, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_REWARDED, onEvent);
			_admob.addEventListener(AdEvent.REWARDED_STARTED, onEvent);
			_admob.init();
		}
	}

}

 

Then I added this line to the script, it's sitting on the top root and not part of a function or anything else. I'm not sure if it's supposed to be nested somewhere.

_admob.show("ca-app-pub-3940256099942544/6300978111", AdParams.SIZE_SMART_BANNER, AdParams.HALIGN_CENTER, AdParams.VALIGN_BOTTOM);

 

with this above settings when trying to compile the code I get the following error message:

"Main.as, Line 1 5006: An ActionScript file can not have more than one externally visible definition: _admob, Main"

 

  1. Why I'm getting this error message?
  2. Is this code is proper to run adMob?
  3. am I missing something?

Views

635

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

Hi.

 

Variable declaration cannot happen inside of package blocks. Move the variable line to the class block. Like this:

package
{
	import flash.display.MovieClip;
	import com.pozirk.ads.admob.AdMob;
	import com.pozirk.ads.admob.AdParams;
	import com.pozirk.ads.admob.AdEvent;

	public class Main extends MovieClip
	{
		var _admob: AdMob = new AdMob();

		public function Main()
		{
			// ...
		}
	}
}

 

I hope this helps.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

Also, I created a sample using this ANE a couple of years ago, in case you're interested.

http://bit.ly/2I2oy6i

 

I can't say if the code still works because the Google Play rules change a lot, but maybe you can still use it as a reference.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 29, 2020 Oct 29, 2020

Copy link to clipboard

Copied

LATEST

As far as I know, you wont be able to fullfill the new Admob / Google requirements with porzik. Their last version is from 3 months ago and there are new issues on requesting consent from EU users to show ads.

 

I would suggest you to take a look to https://airnativeextensions.com/

 

Here is more info: https://docs.airnativeextensions.com/docs/adverts/

 

They have updated their Adverts ANE in order to fullfill all the new requirements from Admob.

 

Best,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines