package com.alchemyadlabs.components{ import com.alchemyadlabs.utilities.Reporting; import com.alchemyadlabs.components.MediaPlayer; import com.alchemyadlabs.components.MediaLoader; import com.alchemyadlabs.NotificationConstants; import com.greensock.TweenLite; import com.greensock.TweenMax; import flash.display.MovieClip; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.display.Graphics; import flash.display.Shape; import flash.display.Sprite; import flash.system.Security; import flash.events.ProgressEvent; import flash.events.Event; import flash.external.ExternalInterface; import flash.net.navigateToURL; import flash.net.URLRequest; import com.greensock.easing.Strong; import flash.net.URLRequest; import flash.utils.setTimeout; public class MicrositePlayer extends MovieClip { Security.allowDomain("*"); //PREROLL //media player private var posterURL:String = "assets/videoButton.jpg"; private var _mediaPlayer:MediaPlayer; private var _mediaPlayerParams:Object; private var isMediaPlayerSmall:Boolean = false; // video player //private var preRollURL:String = "http://imagen01.247realmedia.com/RealMedia/ads/Creatives/USNetwork/ALCHEMY_CREATIVES_HOLDER/10012013_JustMe_GMC_Video_15.flv"; //private var preRollURL:String = "http://imagen01.247realmedia.com/RealMedia/ads/Creatives/USNetwork/ALCHEMY_CREATIVES_HOLDER/10012013_3on1_GMC_Video_15.flv"; //private var preRollURL:String = "http://imagen01.247realmedia.com/RealMedia/ads/Creatives/USNetwork/ALCHEMY_CREATIVES_HOLDER/10012013_LoadingUp_GMC_Video_15.flv"; private var preRollURL:String = "https://networkadmin.realmedia.com/RealMedia/ads/Creatives/Alchemy/20140103/JewelersMutual_Laughlin_Spotlight_001_BCN2013100507_132014/JMI_crab_15HD_1080p.mp4"; private var preRollHasPlayed:Boolean = false; private var preRollHasStarted:Boolean = false; private var preRollHasPlayedQ1:Boolean = false; private var preRollHasPlayedMid:Boolean = false; private var preRollHasPlayedQ3:Boolean = false; //Chapter reporting private var sectionOneHasReported:Boolean = false; private var sectionTwoHasReported:Boolean = false; private var sectionThreeHasReported:Boolean = false; private var sectionFourHasReported:Boolean = false; private var sectionFiveHasReported:Boolean = false; private var sectionSixHasReported:Boolean = false; private var sectionSevenHasReported:Boolean = false; private var parentObj:* = null; // tracking constants public static const AD_IMPRESSION:String = "AD_IMPRESSION"; public static const CREATIVE_CLICK_URL:String = "CREATIVE_CLICK_URL"; public static const PRE_ROLL_CLICK_URL:String = "http://www.perfectcircleinsurance.com/"; public static const PRE_ROLL_CLICK_IMPRESSION_1:String = "PRE_ROLL_CLICK_IMPRESSION_1"; public static const PRE_ROLL_CLICK_IMPRESSION_2:String = "PRE_ROLL_CLICK_IMPRESSION_2"; public static const PRE_ROLL_CLICK_IMPRESSION_3:String = "PRE_ROLL_CLICK_IMPRESSION_3"; private var preRollClickReportingArray:Array = [PRE_ROLL_CLICK_IMPRESSION_1, PRE_ROLL_CLICK_IMPRESSION_2, PRE_ROLL_CLICK_IMPRESSION_3]; public static const PRE_ROLL_START_IMPRESSION_1:String = "PRE_ROLL_START_IMPRESSION_1"; public static const PRE_ROLL_START_IMPRESSION_2:String = "PRE_ROLL_START_IMPRESSION_2"; public static const PRE_ROLL_START_IMPRESSION_3:String = "PRE_ROLL_START_IMPRESSION_3"; private var preRollStartReportingArray:Array = [PRE_ROLL_START_IMPRESSION_1, PRE_ROLL_START_IMPRESSION_2, PRE_ROLL_START_IMPRESSION_3]; public static const PRE_ROLL_FIRST_QUARTILE_IMPRESSION_1:String = "PRE_ROLL_FIRST_QUARTILE_IMPRESSION_1"; public static const PRE_ROLL_FIRST_QUARTILE_IMPRESSION_2:String = "PRE_ROLL_FIRST_QUARTILE_IMPRESSION_2"; public static const PRE_ROLL_FIRST_QUARTILE_IMPRESSION_3:String = "PRE_ROLL_FIRST_QUARTILE_IMPRESSION_3"; private var preRollFirstReportingArray:Array = [PRE_ROLL_FIRST_QUARTILE_IMPRESSION_1, PRE_ROLL_FIRST_QUARTILE_IMPRESSION_2, PRE_ROLL_FIRST_QUARTILE_IMPRESSION_3]; public static const PRE_ROLL_MID_QUARTILE_IMPRESSION_1:String = "PRE_ROLL_MID_QUARTILE_IMPRESSION_1"; public static const PRE_ROLL_MID_QUARTILE_IMPRESSION_2:String = "PRE_ROLL_MID_QUARTILE_IMPRESSION_2"; public static const PRE_ROLL_MID_QUARTILE_IMPRESSION_3:String = "PRE_ROLL_MID_QUARTILE_IMPRESSION_3"; private var preRollMidReportingArray:Array = [PRE_ROLL_MID_QUARTILE_IMPRESSION_1, PRE_ROLL_MID_QUARTILE_IMPRESSION_2, PRE_ROLL_MID_QUARTILE_IMPRESSION_3]; public static const PRE_ROLL_THIRD_QUARTILE_IMPRESSION_1:String = "PRE_ROLL_THIRD_QUARTILE_IMPRESSION_1"; public static const PRE_ROLL_THIRD_QUARTILE_IMPRESSION_2:String = "PRE_ROLL_THIRD_QUARTILE_IMPRESSION_2"; public static const PRE_ROLL_THIRD_QUARTILE_IMPRESSION_3:String = "PRE_ROLL_THIRD_QUARTILE_IMPRESSION_3"; private var preRollThirdReportingArray:Array = [PRE_ROLL_THIRD_QUARTILE_IMPRESSION_1, PRE_ROLL_THIRD_QUARTILE_IMPRESSION_2, PRE_ROLL_THIRD_QUARTILE_IMPRESSION_3]; public static const PRE_ROLL_END_QUARTILE_IMPRESSION_1:String = "PRE_ROLL_END_QUARTILE_IMPRESSION_1"; public static const PRE_ROLL_END_QUARTILE_IMPRESSION_2:String = "PRE_ROLL_END_QUARTILE_IMPRESSION_2"; public static const PRE_ROLL_END_QUARTILE_IMPRESSION_3:String = "PRE_ROLL_END_QUARTILE_IMPRESSION_3"; private var preRollEndReportingArray:Array = [PRE_ROLL_END_QUARTILE_IMPRESSION_1, PRE_ROLL_END_QUARTILE_IMPRESSION_2, PRE_ROLL_END_QUARTILE_IMPRESSION_3]; private var videoOneURL:String = "http://imagen01.247realmedia.com/RealMedia/ads/Creatives/USNetwork/ALCHEMY_CREATIVES_HOLDER/10012013_Walkaround_GMC_Full.flv"; public static const VIDEO_ONE_CLICK_URL:String = "http://ad-emea.doubleclick.net/clk;276398295;103575641;s"; public static const VIDEO_ONE_CLICK_IMPRESSION_1:String = "VIDEO_ONE_CLICK_IMPRESSION_1"; public static const VIDEO_ONE_CLICK_IMPRESSION_2:String = "VIDEO_ONE_CLICK_IMPRESSION_2"; public static const VIDEO_ONE_CLICK_IMPRESSION_3:String = "VIDEO_ONE_CLICK_IMPRESSION_3"; private var videoOneClickReportingArray:Array = [VIDEO_ONE_CLICK_IMPRESSION_1, VIDEO_ONE_CLICK_IMPRESSION_2, VIDEO_ONE_CLICK_IMPRESSION_3]; public function MicrositePlayer() { //this.loaderInfo.addEventListener(Event.COMPLETE, adStart); } public function setParent(_parentObj:*) { trace("Parent Object Set: %%%% -> " + _parentObj); parentObj = _parentObj; adStart(); } public function adStart():void { initMediaPlayer(); } /////////////////////////// // MEDIA PLAYERS SET-UP // ////////////////////////// private function initMediaPlayer():void { /*oParent nContainerX = x offset of the loader container nContainerY = y offset of the loader container nMediaX = x offset of the image/poster media nMediaY = y offset of the image/poster media nVideoX = x offset of the video media nVideoY = y offset of the video media sMediaPlayerName = unique string name of the current instance nMediaLoaderWidth = width of the loader (video and media will scale to fit) nMediaLoaderHeight = height of the loader (video and media will scale to fit) */ var mediaPlayerInitObj = new Object(); mediaPlayerInitObj.oParent = this; mediaPlayerInitObj.nMediaLoaderHeight = parentObj.insVidOne.height; mediaPlayerInitObj.nMediaLoaderWidth = parentObj.insVidOne.width; mediaPlayerInitObj.sMediaPlayerName = "insVidOne"; mediaPlayerInitObj.bVideoLooping = false; mediaPlayerInitObj.nVideoVolume = .5; //add playlist mediaPlayerInitObj.bPlaylistAutoPlay = false; mediaPlayerInitObj.aPlaylistArray = new Array(); //mediaPlayerInitObj.bVideoMuted = true; _mediaPlayer = new MediaPlayer(); _mediaPlayer.y = parentObj.insVidOne.y; _mediaPlayer.x = parentObj.insVidOne.x; parentObj.addChild(_mediaPlayer); _mediaPlayerParams = new Object; _mediaPlayerParams.oParent = this; _mediaPlayer.init(mediaPlayerInitObj); //_mediaPlayer.loadImage(posterURL, true); _mediaPlayer.initVideo(preRollURL, true); var startVidTimeout:uint = setTimeout(function() { }, 1500); this.addEventListener(Event.ENTER_FRAME, checkChapterMarkers); initPlaylist(); //setTimeout(function() {_mediaPlayer.fadeVolume("in", .5)}, 3000); } public function playVideo(){ _mediaPlayer.playVideo(null); } public function pauseVideo(){ _mediaPlayer.pauseVideo(null); } public function hideVideoPlayer(){ isMediaPlayerSmall=true; TweenLite.to(_mediaPlayer, 1, {x:650, y:320, scaleX:0.15, scaleY:0.15}); //_mediaPlayer.scaleX=.25; //_mediaPlayer.scaleY=.25; //TweenLite.to(_mediaPlayer, .25, {alpha:0}); } public function showVideoPlayer(){ isMediaPlayerSmall=false; //_mediaPlayer.visible=true; trace("EXPANDINNN!!!"); TweenLite.to(_mediaPlayer, 1, {x:148, y:75, scaleX:1, scaleY:1}); parentObj.expandVideoPlayer(); //TweenLite.to(_mediaPlayer, .25, {alpha:1}); } private function videoLoaded(e:Event):void{ _mediaPlayer.handlePauseSlateClick(null); } public function muteVidVolume():void{ trace("$$$$$$$$$$$$$$ MUTE VID VOLUME"); //_mediaPlayer.fadeVolume("out", .01); _mediaPlayer.setVideoVolume(0.0001); //trace(_mediaPlayer.fadeVolume("out",-1)); } public function unmuteVidVolume():void{ _mediaPlayer.setVideoVolume(.5); } private function checkChapterMarkers(e:Event):void { if(_mediaPlayer.getVideoUrl() == videoOneURL) { var currentTime = _mediaPlayer.getTime(); if(currentTime >= 0 && currentTime < 16) { if(!sectionOneHasReported) { trace("Reporting Section One"); reportImp("panache_generic_event_07"); sectionOneHasReported = true; } } if(currentTime >= 16 && currentTime < 39) { if(!sectionTwoHasReported) { trace("Reporting Section Two"); reportImp("panache_generic_event_08"); sectionTwoHasReported = true; } } if(currentTime >= 39 && currentTime < 69) { if(!sectionThreeHasReported) { trace("Reporting Section Three"); reportImp("panache_generic_event_09"); sectionThreeHasReported = true; } } if(currentTime >= 69 && currentTime < 100) { if(!sectionFourHasReported) { trace("Reporting Section Four"); reportImp("panache_generic_event_10"); sectionFourHasReported = true; } } if(currentTime >= 100 && currentTime < 131) { if(!sectionFiveHasReported) { trace("Reporting Section Five"); reportImp("panache_generic_event_11"); sectionFiveHasReported = true; } } if(currentTime >= 131 && currentTime < 163) { if(!sectionSixHasReported) { trace("Reporting Section Six"); reportImp("panache_generic_event_12"); sectionSixHasReported = true; } } if(currentTime >= 163 && currentTime < 223) { if(!sectionSevenHasReported) { trace("Reporting Section Seven"); reportImp("panache_generic_event_13"); sectionSevenHasReported = true; } } if(currentTime >= 223 && currentTime < 267) { trace("Reporting Section Eight"); } } } private function reportImp(imp:String):void { if(parentObj != null) { parentObj.requestTracking(imp); } } private function initPlaylist():void { } private function handlePlaylistClick(e:MouseEvent):void { trace(e.target.name); switch(e.target.name) { case "playlist1": _mediaPlayer.initVideo(videoOneURL, true); break; case "playlist2": break; case "playlist3": break; } } public function handleControllerNotification(notObj:Object) { var notificationName = notObj["notificationName"]; var reportingObject:Object = new Object(); switch(notificationName) { case NotificationConstants.MEDIA_LOADED: if(notObj.notifierName == "background-image") { initMediaPlayer(); } break; case NotificationConstants.CREATIVE_CLICK_NOTIFICATION: //Report creative click reportingObject.impName = NotificationConstants.CREATIVE_CLICK_NOTIFICATION; reportingObject.impURL = CREATIVE_CLICK_URL; Reporting.reportImp(reportingObject); break; case NotificationConstants.VIDEO_CLICK_NOTIFICATION: handleVideoClickReporting(notObj); break; case NotificationConstants.VIDEO_REPORTING_NOTIFICATION: handleVideoReporting(notObj); break; } reportingObject = null; } public function handleVideoClickReporting(notObj:Object):void { var reportingObject:Object = new Object(); //trace(notObj.notifierUrl); switch(notObj.notifierUrl) { case preRollURL: if (!isMediaPlayerSmall){ reportingObject.impName = NotificationConstants.VIDEO_CLICK_NOTIFICATION; reportingObject.arrayOfLinks = preRollClickReportingArray; Reporting.reportImp(reportingObject); navigateToURL(new URLRequest(MicrositePlayer.PRE_ROLL_CLICK_URL), "_blank"); //reportImp("track_video_click"); reportImp("panache_generic_event_06"); } else {showVideoPlayer();setTimeout(function(){_mediaPlayer.playVideo();},1000)} break; case videoOneURL: reportingObject.impName = NotificationConstants.VIDEO_CLICK_NOTIFICATION; reportingObject.arrayOfLinks = videoOneClickReportingArray; Reporting.reportImp(reportingObject); navigateToURL(new URLRequest(MicrositePlayer.VIDEO_ONE_CLICK_URL), "_blank"); reportImp("panache_generic_event_06"); break; } } public function handlCreativeClicks():void { } private function handleVideoReporting(notObj:Object):void { //We should only report video events for preroll video if(preRollHasPlayed && notObj.notifierUrl == preRollURL) { switch(notObj.notificationEvent){ case NotificationConstants.VIDEO_END_EVENT: //_mediaPlayer.visible=false; //parentObj.insVidOne.visible=false; _mediaPlayer.rewindVideo(); break; } return; } var reportingObject:Object = new Object(); switch(notObj.notificationEvent) { case NotificationConstants.VIDEO_START_EVENT_NOTIFICATION: if(notObj.notifierUrl == preRollURL && preRollHasStarted == false) { reportingObject.impName = NotificationConstants.VIDEO_START_EVENT_NOTIFICATION; reportingObject.arrayOfLinks = preRollStartReportingArray; Reporting.reportImp(reportingObject); preRollHasStarted = true; trace(NotificationConstants.VIDEO_START_EVENT_NOTIFICATION); //reportImp('video_start'); reportImp('panache_generic_event_16'); //requestTracking('track_video_start'); } break; case NotificationConstants.VIDEO_FIRST_QUARTILE_EVENT_NOTIFICATION: if(notObj.notifierUrl == preRollURL && preRollHasPlayedQ1 == false) { reportingObject.impName = NotificationConstants.VIDEO_FIRST_QUARTILE_EVENT_NOTIFICATION; reportingObject.arrayOfLinks = preRollFirstReportingArray; Reporting.reportImp(reportingObject); preRollHasPlayedQ1 = true; trace(NotificationConstants.VIDEO_FIRST_QUARTILE_EVENT_NOTIFICATION); //reportImp("video_quartile1"); reportImp('panache_generic_event_17'); } break; case NotificationConstants.VIDEO_MID_EVENT_NOTIFICATION: if(notObj.notifierUrl == preRollURL && preRollHasPlayedMid == false) { reportingObject.impName = NotificationConstants.VIDEO_MID_EVENT_NOTIFICATION; reportingObject.arrayOfLinks = preRollMidReportingArray; Reporting.reportImp(reportingObject); preRollHasPlayedMid = true; trace(NotificationConstants.VIDEO_MID_EVENT_NOTIFICATION); //reportImp("video_midpoint"); reportImp('panache_generic_event_18'); } break; case NotificationConstants.VIDEO_THIRD_QUARTILE_EVENT_NOTIFICATION: if(notObj.notifierUrl == preRollURL && preRollHasPlayedQ3 == false) { reportingObject.impName = NotificationConstants.VIDEO_THIRD_QUARTILE_EVENT_NOTIFICATION; reportingObject.arrayOfLinks = preRollThirdReportingArray; Reporting.reportImp(reportingObject); preRollHasPlayedQ3 = true; trace(NotificationConstants.VIDEO_THIRD_QUARTILE_EVENT_NOTIFICATION); //reportImp("video_quartile3"); reportImp('panache_generic_event_19'); } break; case NotificationConstants.VIDEO_END_EVENT: if(notObj.notifierUrl == preRollURL && preRollHasPlayed == false) { reportingObject.impName = NotificationConstants.VIDEO_END_EVENT; reportingObject.arrayOfLinks = preRollEndReportingArray; Reporting.reportImp(reportingObject); preRollHasPlayed = true; trace(NotificationConstants.VIDEO_END_EVENT); //reportImp("video_end"); reportImp('panache_generic_event_20'); //_mediaPlayer.visible=false; //parentObj.insVidOne.visible=false; parentObj.startSwitchAnimation(); } break; } } } }