Permalink
Browse files

Support for closing ads when identityCountdown is set to true

  • Loading branch information...
1 parent 0e4a0d7 commit 3ac2f708515b3e6ad409ff2d9c2350b10004819b @steffentchr committed Jan 28, 2012
Showing with 53 additions and 21 deletions.
  1. +12 −2 src/AppProperties.as
  2. +7 −0 src/VideoPlayer.mxml
  3. +34 −19 src/com/visual/VisualAds.as
View
@@ -1,4 +1,6 @@
// ActionScript file
+import flash.events.Event;
+
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.ResizeEvent;
@@ -269,14 +271,22 @@ private function bootstrapAds():void {
// Interface with the app through events
ads.addEventListener('contentPauseRequested', function():void{
+ if(props.getBoolean('identityAllowClose') && props.getBoolean('identityCountdown')) {
+ adMessage.visible = true;
+ adMessage.message = '';
+ adMessage.addEventListener(Event.CLOSE, function(e:Event):void{
+ ads.stop();
+ });
+ }
forceHideTray = true;
trayHide();
- pauseVideoElement()
+ pauseVideoElement();
});
ads.addEventListener('contentResumeRequested', function():void{
forceHideTray = false;
+ adMessage.visible = false;
trayShow();
- playVideoElement()
+ playVideoElement();
});
// Append sources
View
@@ -404,6 +404,13 @@
clipContent="true"
width="100%"
height="{(tray.visible ? tray.y+(descriptions.visible?0:descriptions.height) : FlexGlobals.topLevelApplication.height)}" />
+ <com:OverlayMessage id="adMessage"
+ fontFamily="{props.get('trayFont')}"
+ color="{(styleManager.getColorName(props.get('trayTextColor')) as Number)}"
+ backgroundColor="{(styleManager.getColorName(props.get('trayBackgroundColor')) as Number)}"
+ allowClose="{props.get('identityAllowClose')}"
+ visible="false"
+ />
<!-- Tray -->
<mx:Canvas id="tray"
@@ -1,11 +1,8 @@
-// Place overlay correctly (top?)
-// Make sure we do dynamic loading
-// Make VAST/InStream part of PlayFlow
-
package com.visual {
import com.google.ads.instream.api.Ad;
import com.google.ads.instream.api.AdErrorEvent;
import com.google.ads.instream.api.AdEvent;
+ import com.google.ads.instream.api.AdLoadedEvent;
import com.google.ads.instream.api.AdSizeChangedEvent;
import com.google.ads.instream.api.AdsLoadedEvent;
import com.google.ads.instream.api.AdsLoader;
@@ -20,6 +17,7 @@ package com.visual {
import flash.events.Event;
import flash.geom.Point;
import flash.media.Video;
+ import flash.net.NetStream;
import mx.core.UIComponent;
import mx.events.ResizeEvent;
@@ -31,8 +29,9 @@ package com.visual {
private var loader:AdsLoader;
private var manager:AdsManager;
private var requests:Array = [];
- private var internalVideo:Video = null;
private var internalFlash:UIComponent = null;
+ private var internalVideo:Video = null;
+ private var ns:NetStream = null;
public function VisualAds() {
super();
@@ -59,19 +58,21 @@ package com.visual {
private function load(type:String):Boolean {
for (var i:int=0; i<requests.length; i++){
var req:Object = requests[i];
- if(req.type==type) {
- var request:AdsRequest = new AdsRequest();
- request.adType = req.type;
- request.adTagUrl = req.url;
- request.publisherId = req.publisherId;
- request.contentId = req.contentId;
- request.adSlotWidth = this.width;
- request.adSlotHeight = this.height;
- requests.push(request);
- loader.requestAds(request);
- this.visible = true;
- return(true);
- }
+ try {
+ if(typeof(req.type)!='undefined' && req.type==type) {
+ var request:AdsRequest = new AdsRequest();
+ request.adType = req.type;
+ request.adTagUrl = req.url;
+ request.publisherId = req.publisherId;
+ request.contentId = req.contentId;
+ request.adSlotWidth = this.width;
+ request.adSlotHeight = this.height;
+ requests.push(request);
+ loader.requestAds(request);
+ this.visible = true;
+ return(true);
+ }
+ }catch(e:Object){}
}
return(false);
}
@@ -89,11 +90,15 @@ package com.visual {
}
private function onVideoAdComplete(e:AdEvent):void {
// Remove video element if applicable
- (manager as VideoAdsManager).clickTrackingElement = null;
+ (manager as VideoAdsManager).clickTrackingElement = null;
this.internalVideo.visible = false;
this.internalVideo.clear();
}
+ private function onAdLoaded(e:AdLoadedEvent):void {
+ ns = e.netStream;
+ }
+
private function onAdsLoaded(e:AdsLoadedEvent):void {
// Clear previous Flash ad stages
try {
@@ -104,6 +109,7 @@ package com.visual {
manager.addEventListener(AdErrorEvent.AD_ERROR, onAdError);
manager.addEventListener(AdEvent.CONTENT_PAUSE_REQUESTED, onContentPauseRequested);
manager.addEventListener(AdEvent.CONTENT_RESUME_REQUESTED, onContentResumeRequested);
+ manager.addEventListener(AdLoadedEvent.LOADED, onAdLoaded);
if (manager.type == AdsManagerTypes.FLASH) {
var flashAdsManager:FlashAdsManager = e.adsManager as FlashAdsManager;
@@ -152,5 +158,14 @@ package com.visual {
flashAdsManager.adSlotWidth = this.width;
}
}
+
+ public function stop():void{
+ try {
+ manager.unload();
+ if(ns) ns.close();
+ onVideoAdComplete(null);
+ }catch(e:Object){}
+ dispatchEvent(new Event('contentResumeRequested'));
+ }
}
}

0 comments on commit 3ac2f70

Please sign in to comment.