A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3 How to add adMob to Adobe Flash/Animate?

  1. #1
    Registered User
    Join Date
    Oct 2020
    Posts
    1

    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:

    PHP 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 
    _admobAdMob = new AdMob();
    public class 
    Main extends MovieClip{
        
            public function 
    Main(){
            
                
    //> initialization of AdMob
                
    _admob.addEventListener(AdEvent.INIT_OKonEvent);
                
    _admob.addEventListener(AdEvent.INIT_FAILonEvent);
                
    _admob.addEventListener(AdEvent.BANNER_SHOW_OKonEvent);
                
    _admob.addEventListener(AdEvent.BANNER_SHOW_FAILonEvent);
                
    _admob.addEventListener(AdEvent.BANNER_LEFT_APPonEvent);
                
    _admob.addEventListener(AdEvent.BANNER_OPENEDonEvent);
                
    _admob.addEventListener(AdEvent.BANNER_CLOSEDonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_SHOW_OKonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_SHOW_FAILonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_CACHE_OKonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_CACHE_FAILonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_LEFT_APPonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_OPENEDonEvent);
                
    _admob.addEventListener(AdEvent.INTERSTITIAL_CLOSEDonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_CACHE_FAILonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_CACHE_OKonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_CLOSEDonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_COMPLETEDonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_LEFT_APPonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_OPENEDonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_REWARDEDonEvent);
                
    _admob.addEventListener(AdEvent.REWARDED_STARTEDonEvent);
                
    _admob.init();
            }
        }


    4. 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.

    PHP Code:
    _admob.show("ca-app-pub-3940256099942544/6300978111"AdParams.SIZE_SMART_BANNERAdParams.HALIGN_CENTERAdParams.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"

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

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,818
    The thing that makes the most sense is you need to add private/public to the _admob var:
    private var _admob: AdMob = new AdMob();
    Also, another possibility is you need to place that inside the class definition instead of out of it.
    .

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Posts
    1
    function onEvent(e:*){
    trace(e)
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center