守望者--AIR技术交流

标题: 百度ane插件,百度移动广告联盟as3版本插件 [打印本页]

作者: 破晓    时间: 2014-12-30 14:23
标题: 百度ane插件,百度移动广告联盟as3版本插件
相关链接:
http://www.airmyth.com/forum.php?mod=viewthread&tid=28

http://www.airmyth.com/forum.php?mod=viewthread&tid=29


上一篇发布了百度广告
ane使用教程,为了aser们方便在一个应用中同时使用百度和admob广告,特此再发布一个百度ane的插件。这个插件是adobe flash air ad network framework的一个扩展(https://code.google.com/p/adoble-flash-air-ad-network-framework/),
只需要把代码保存为BaiduAdapter.as结合adobe air广告框架就可以非常方便的在一个air移动应用中添加admob广告和百度广告。百度ane下载地址:https://code.google.com/p/baidu-ane/




  1. package so.cuo.platform.ad.adapters
  2. {
  3.         import com.baidu.mobads.BaiDu;
  4.         import com.baidu.mobads.BaiDuAdEvent;
  5.         import com.baidu.mobads.BaiDuSize;
  6.         
  7.         import flash.events.Event;
  8.         import flash.events.EventDispatcher;
  9.         
  10.         import so.cuo.platform.ad.AdEvent;
  11.         import so.cuo.platform.ad.AdSize;
  12.         import so.cuo.platform.ad.IBanner;
  13.         import so.cuo.platform.ad.IInterstitial;

  14.         [Event(name="onBannerDismiss", type="so.cuo.platform.ad.AdEvent")]
  15.         [Event(name="onBannerFailedReceive", type="so.cuo.platform.ad.AdEvent")]
  16.         [Event(name="onBannerLeaveApplication", type="so.cuo.platform.ad.AdEvent")]
  17.         [Event(name="onBannerPresent", type="so.cuo.platform.ad.AdEvent")]
  18.         [Event(name="onBannerReceive", type="so.cuo.platform.ad.AdEvent")]
  19.         [Event(name="onInterstitialDismiss", type="so.cuo.platform.ad.AdEvent")]
  20.         [Event(name="onInterstitialFailedReceive", type="so.cuo.platform.ad.AdEvent")]
  21.         [Event(name="onInterstitialLeaveApplication", type="so.cuo.platform.ad.AdEvent")]
  22.         [Event(name="onInterstitialPresent", type="so.cuo.platform.ad.AdEvent")]
  23.         [Event(name="onInterstitialReceive", type="so.cuo.platform.ad.AdEvent")]
  24.         public class BaiduAdapter extends EventDispatcher implements  IBanner, IInterstitial
  25.         {
  26.                 protected static const banners:Vector.<AdSize>=new Vector.<AdSize>();
  27. //                protected var key:String;
  28.                 protected function get plat():BaiDu{
  29.                         return BaiDu.getInstance();
  30.                 }
  31.                 public function BaiduAdapter()
  32.                 {
  33.                         plat.addEventListener(BaiDuAdEvent.onBannerDismiss,onAdHandler);
  34.                         plat.addEventListener(BaiDuAdEvent.onBannerFailedReceive,onAdHandler);
  35.                         plat.addEventListener(BaiDuAdEvent.onBannerLeaveApplication,onAdHandler);
  36.                         plat.addEventListener(BaiDuAdEvent.onBannerPresent,onAdHandler);
  37.                         plat.addEventListener(BaiDuAdEvent.onBannerReceive,onAdHandler);
  38.                         
  39.                         plat.addEventListener(BaiDuAdEvent.onInterstitialDismiss,onAdHandler);
  40.                         plat.addEventListener(BaiDuAdEvent.onInterstitialFailedReceive,onAdHandler);
  41.                         plat.addEventListener(BaiDuAdEvent.onInterstitialLeaveApplication,onAdHandler);
  42.                         plat.addEventListener(BaiDuAdEvent.onInterstitialPresent,onAdHandler);
  43.                         plat.addEventListener(BaiDuAdEvent.onInterstitialReceive,onAdHandler);
  44.                         initBannerSize();
  45.                 }
  46.                 protected function initBannerSize():void
  47.                 {
  48.                         banners[AdSize.PHONE_PORTRAIT]=new AdSize(BaiDu.BANNER.width,BaiDu.BANNER.height);
  49.                         banners[AdSize.PHONE_LANDSCAPE]=new AdSize(BaiDu.IAB_BANNER.width,BaiDu.IAB_BANNER.height);
  50.                         banners[AdSize.PAD_PORTRAIT]=new AdSize(BaiDu.IAB_LEADERBOARD.width,BaiDu.IAB_LEADERBOARD.height);
  51.                         banners[AdSize.PAD_LANDSCAPE]=new AdSize(BaiDu.IAB_LEADERBOARD.width,BaiDu.IAB_LEADERBOARD.height);
  52.                         banners[AdSize.IAB_MRECT]=new AdSize(BaiDu.IAB_MRECT.width,BaiDu.IAB_MRECT.height);
  53.                 }
  54.                
  55.                 public function get supportDevice():Boolean
  56.                 {
  57.                         return plat.supportDevice;
  58.                 }
  59.                
  60.                 public function setTesting(deviceID:String=null):void
  61.                 {
  62.                 }
  63.                
  64.                 public function onAdHandler(e:Event):void
  65.                 {
  66.                         var ae:BaiDuAdEvent=e as BaiDuAdEvent;
  67.                         if(ae.data!=null&&(ae.data is BaiDuSize)){
  68.                                 var size:BaiDuSize=ae.data as  BaiDuSize;
  69.                                 this.dispatchEvent(new AdEvent(e.type,new AdSize(size.width,size.height)));
  70.                         }else{
  71.                                 this.dispatchEvent(new AdEvent(e.type,(e as BaiDuAdEvent).data));
  72.                         }
  73.                 }
  74.                
  75.                 public function dispose():void
  76.                 {
  77.                         plat.removeEventListener(BaiDuAdEvent.onBannerDismiss,onAdHandler);
  78.                         plat.removeEventListener(BaiDuAdEvent.onBannerFailedReceive,onAdHandler);
  79.                         plat.removeEventListener(BaiDuAdEvent.onBannerLeaveApplication,onAdHandler);
  80.                         plat.removeEventListener(BaiDuAdEvent.onBannerPresent,onAdHandler);
  81.                         plat.removeEventListener(BaiDuAdEvent.onBannerReceive,onAdHandler);
  82.                         
  83.                         plat.removeEventListener(BaiDuAdEvent.onInterstitialDismiss,onAdHandler);
  84.                         plat.removeEventListener(BaiDuAdEvent.onInterstitialFailedReceive,onAdHandler);
  85.                         plat.removeEventListener(BaiDuAdEvent.onInterstitialLeaveApplication,onAdHandler);
  86.                         plat.removeEventListener(BaiDuAdEvent.onInterstitialPresent,onAdHandler);
  87.                         plat.removeEventListener(BaiDuAdEvent.onInterstitialReceive,onAdHandler);
  88.                 }

  89.                 public function setInterstitialKeys(appID:String, key:String=null):void
  90.                 {
  91.                         plat.setKeys(appID,key);
  92.                 }

  93.                 public function cacheInterstitial():void
  94.                 {
  95.                         plat.cacheInterstitial();
  96.                 }

  97.                 public function showInterstitial():void
  98.                 {
  99.                         plat.showInterstitial();
  100.                 }

  101.                 public function isInterstitialReady():Boolean
  102.                 {
  103.                         return plat.isInterstitialReady();
  104.                 }

  105.                 public function get supportedInterstitial():Boolean
  106.                 {
  107.                         return true;
  108.                 }

  109.                 public function setBannerKeys(appID:String, key:String=null):void
  110.                 {
  111.                         plat.setKeys(appID,key);
  112.                 }

  113.                 public function showBanner(adSize:AdSize, position:int):void
  114.                 {
  115.                         plat.showBanner(new BaiDuSize(adSize.width,adSize.height),position);
  116.                 }

  117.                 public function showBannerAbsolute(adSize:AdSize, x:Number, y:Number):void
  118.                 {
  119.                         plat.showBannerAbsolute(new BaiDuSize(adSize.width,adSize.height),x,y);
  120.                 }

  121.                 public function hideBanner():void
  122.                 {
  123.                         plat.hideBanner();
  124.                 }

  125.                 public function getBannerSize(type:int):AdSize
  126.                 {
  127.                         if(type<banners.length&&type>=0){
  128.                                 return banners[type];
  129.                         }
  130.                         return new AdSize(BaiDu.BANNER.width,BaiDu.BANNER.height);
  131.                 }

  132.                 public function get supportedBanner():Boolean
  133.                 {
  134.                         return true;
  135.                 }
  136.         }
  137. }
复制代码







欢迎光临 守望者--AIR技术交流 (http://www.airmyth.com/)