Created
November 7, 2015 00:12
-
-
Save astein/eac71b443ef209b8a5fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.truex.placements.extensions | |
{ | |
import flash.display.Sprite; | |
import flash.external.ExternalInterface; | |
import flash.system.Security; | |
import flash.utils.setTimeout; | |
import tv.freewheel.ad.behavior.IAdManager; | |
import tv.freewheel.ad.behavior.IConstants; | |
import tv.freewheel.ad.behavior.IEvent; | |
import tv.freewheel.ad.behavior.IExtension; | |
import tv.freewheel.ad.behavior.ISlot; | |
public class TrueXExtension extends Sprite implements IExtension | |
{ | |
private var _adManager:IAdManager; | |
private var _constants:IConstants; | |
private var _streamFreeEnabled:Boolean; | |
public function TrueXExtension() | |
{ | |
Security.allowDomain('*'); | |
} | |
public function init(am:IAdManager):void | |
{ | |
_adManager = am; | |
if(_adManager) { | |
_constants = _adManager.getConstants(); | |
_adManager.addEventListener(_constants.EVENT_CUSTOM, onCustomEvent); | |
_adManager.addEventListener(_constants.EVENT_SLOT_PRELOADED, onSlotPreloaded); | |
_adManager.addEventListener(_constants.EVENT_SLOT_STARTED, onSlotStarted); | |
} | |
} | |
private function onCustomEvent(e:IEvent):void | |
{ | |
if (e.subType == 'truex_credit') { | |
var slot:Object = e.details; | |
if (slot) { | |
slot.stop(); | |
} | |
} else if (e.subType == 'truex_stream_credit') { | |
// rest of the stream is ad-free | |
_streamFreeEnabled = true; | |
} | |
} | |
private function onSlotPreloaded(e:IEvent):void | |
{ | |
if (_streamFreeEnabled) { | |
var slot:ISlot = _adManager.getSlotByCustomId(e.slotCustomId); | |
if (slot && slot.getType() == _constants.SLOT_TYPE_TEMPORAL) { | |
setTimeout(function():void { slot.stop(); }, 0); | |
} | |
} | |
} | |
private function onSlotStarted(e:IEvent):void | |
{ | |
if (_streamFreeEnabled) { | |
var slot:ISlot = _adManager.getSlotByCustomId(e.slotCustomId); | |
if (slot && slot.getType() == _constants.SLOT_TYPE_TEMPORAL) { | |
setTimeout(function():void { slot.stop(true); }, 0); | |
} | |
} | |
} | |
public function dispose():void | |
{ | |
if (_adManager) { | |
_adManager.removeEventListener(_constants.EVENT_CUSTOM, onCustomEvent); | |
_adManager.removeEventListener(_constants.EVENT_SLOT_PRELOADED, onSlotPreloaded); | |
_adManager.removeEventListener(_constants.EVENT_SLOT_STARTED, onSlotStarted); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment