Skip to content

Commit

Permalink
Special companion handling: pushdown + wallpaper code being sent with…
Browse files Browse the repository at this point in the history
… events
  • Loading branch information
thatguystone committed May 8, 2012
1 parent 0fc71ab commit b9a6dcb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
13 changes: 10 additions & 3 deletions src/actionscript/com/iheart/ima/AdPlayer.as
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ package com.iheart.ima {
private var _model:PluginModel;

private var _adInfo:Object
private var _specialCompanions:Object;
private var _currentAd:VideoAd;
private var _companions:CompanionManager = new CompanionManager();
private var _video:Video;
Expand Down Expand Up @@ -190,6 +191,11 @@ package com.iheart.ima {
_adsManager.addEventListener(AdEvent.STARTED, onAdStarted);
_adsManager.addEventListener(AdLoadedEvent.LOADED, onAdLoaded);

//has to happen before the the videoAds calls, otherwise _specialCompanions
//won't be populated for the events
_companions.displayCompanions(_adsManager);
_specialCompanions = _companions.getSpecialCompanions(_adsManager);

if (_adsManager.type == AdsManagerTypes.VIDEO) {
var videoAdsManager:VideoAdsManager = _adsManager as VideoAdsManager;
videoAdsManager.clickTrackingElement = _clickTrackingElement;
Expand All @@ -198,8 +204,6 @@ package com.iheart.ima {
} else {
dispatchError(Errors.UNSUPPORTED_TYPE, 'Creative in response not supported');
}

_companions.displayCompanions(_adsManager);
}

/**
Expand Down Expand Up @@ -256,9 +260,12 @@ package com.iheart.ima {

_adInfo = {
adType: adType,
duration: duration
duration: duration,
companions: _specialCompanions
};

log.info('adloaded');

_model.dispatch(PluginEventType.PLUGIN_EVENT, Events.AD_LOADED, _adInfo);
}

Expand Down
55 changes: 45 additions & 10 deletions src/actionscript/com/iheart/ima/CompanionManager.as
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,69 @@ package com.iheart.ima {
internal class CompanionManager {
private var log:Log = new Log(this);

private const _specialAds:Object = {
wallpaper: [10, 10],
pushdown: [970, 90]
};

public function displayCompanions(adsManager:AdsManager):void {
iterateAds(adsManager, function(ad:Ad):void {
withHtmlAdSize(ad, 300, 250, function(comp:HtmlCompanionAd):void {
renderHtmlCompanionAd(comp, '300x250');
});
});
}

public function getSpecialCompanions(adsManager:AdsManager):Object {
var ret:Object = {};

iterateAds(adsManager, function(ad:Ad):void {
log.info('--1');
for (var k:String in _specialAds) {
var dims:Array = _specialAds[k];

log.info('Loading special companion: ' + k + ' - ' + dims[0] + 'x' + dims[1]);

withHtmlAdSize(ad, dims[0], dims[1], function(comp:HtmlCompanionAd):void {
//strip out HTML tags before sending to the client
ret[k] = comp.content.replace(/<.*?>/g, "");
});
}
});

return ret;
}

private function iterateAds(adsManager:AdsManager, adCallback:Function):void {
log.debug("AdsManager type: " + adsManager.type);

var ads:Array = adsManager.ads;
if (ads) {
log.debug(ads.length + " ads loaded");
for each (var ad:Ad in ads) {
renderHtmlCompanionAd(
ad.getCompanionAds(CompanionAdEnvironments.HTML, 300, 250),
"300x250"
);
adCallback(ad);
}
}
}

private function renderHtmlCompanionAd(companionArray:Array, size:String):void {
private function withHtmlAdSize(ad:Ad, width:int, height:int, compCallback:Function):void {
var companionArray:Array = ad.getCompanionAds(CompanionAdEnvironments.HTML, width, height);

if (companionArray && companionArray.length > 0) {
log.debug("There are " + companionArray.length + " companions for this ad.");
var companion:CompanionAd = companionArray[0] as CompanionAd;
if (companion.environment == CompanionAdEnvironments.HTML) {
log.debug("companion " + size + " environment: " + companion.environment);
var htmlCompanion:HtmlCompanionAd = companion as HtmlCompanionAd;
log.debug("companion " + width + 'x' + height + " environment: " + companion.environment);

if (ExternalInterface.available) {
ExternalInterface.call('writeIntoCompanionDiv', htmlCompanion.content, size);
}
compCallback(companion as HtmlCompanionAd);
}
}
}

private function renderHtmlCompanionAd(htmlCompanion:HtmlCompanionAd, size:String):void {
if (ExternalInterface.available) {
ExternalInterface.call('writeIntoCompanionDiv', htmlCompanion.content, size);
}
}
}
}

0 comments on commit b9a6dcb

Please sign in to comment.