通过AIR Native Extension在AIR应用中加入iAd广告(二) —— Flash Pro篇

通过AIR Native Extension在AIR应用中加入iAd广告(一) —— Flash Builder篇 已经介绍了如果在Flash Builder上使用iAd扩展.今天讲讲如何使用Flash Pro发布程序.

1. 新建AIR for iOS项目;

2. 将上文提到的iAd_signed.ane重命名为iAd_signed.swc;

3. 打开高级ActionScript 3.0设置, 切换到”库路径”面板.把第2步修改的SWC文件添加到类库中;

4. 展开iAd_signed.swc前面的箭头, 双击”链接类型”为”外部”;

5. 编写舞台类

 
package
{

import flash.display.MovieClip;
import flash.events.Event;
import com.adobe.nativeExtensions.AdBanner;
import com.adobe.nativeExtensions.AdBannerEvent;
import com.adobe.nativeExtensions.AdBannerPosition;

public class Main extends MovieClip
{

public function Main()
{
trace(“Init…”);
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
initAD();
}

private function initAD():void
{
AdBanner.adView.startShowingAds(AdBannerPosition.TOP, true);
AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADED, adLoaded);
AdBanner.adView.addEventListener(AdBannerEvent.AD_LOADING_FAILED, adFailed);
AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_STARTING, adStart);
AdBanner.adView.addEventListener(AdBannerEvent.USER_INTERACTION_FINISHED, adFinished);
}

private function adLoaded(event:AdBannerEvent):void
{
trace(“Ad Loaded”);
AdBanner.adView.visible = true;
trace(“leaving: ” + event.leaving);
}

private function adFailed(event:AdBannerEvent):void
{
trace(“Loaded Failded: ” + […]