0

AS3 How to add adMob to Adobe Flash/Animate?

Please help me to figure out how to add adMMob to my Actionscript 3 app. There isn't a 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();
        }
    }

}
  1. 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?
  • Please format your script sample to readability, so the lines are not crammed and all of them are properly indented. – Organis Oct 29 '20 at 18:04
  • I did but it didn't catch on for whatever reason. – Steve Ben-Ari Oct 29 '20 at 18:39
  • can I edit my post? I don't see this option. – Steve Ben-Ari Oct 29 '20 at 18:41
  • I found the itsy bitsy edit link and I re-edit my post like 500 times but the format only partially worked here. so please forgive the format of this post and try to help anyway. thank you. – Steve Ben-Ari Oct 29 '20 at 18:57
  • ok on the 5001 it worked. – Steve Ben-Ari Oct 29 '20 at 19:06
  • Moving variable declaration inside the class is a correct decision. That's why tidily formatted code is always better than messy one. Then, the error you get now, it's easily googlible, for example: https://www.thewhitewood.com/root-content-is-missing-from-package/ – Organis Oct 29 '20 at 21:08

1 Answers1

0

I made a change to the package and moved the var inside the class section.

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 also realized that I probably need to put this statement in a function. which I did. but now I get this error message when compiling the app.

the swf file specified as the root content is missing

function onEvent():void
{
    _admob.show("ca-app-pub-3940256099942544/6300978111", AdParams.SIZE_SMART_BANNER, AdParams.HALIGN_CENTER, AdParams.VALIGN_BOTTOM);
}
  • link your main class to the main class of adobe animate (just write the name of your class) also in the ActionScript setting/library path add ANE/SWC of Pozirk's AdMob Air Native Extension and test it on a mobile device – Yoones Mashayekhi Nov 07 '20 at 22:16