| 1 | /** |
|---|
| 2 | |
|---|
| 3 | * Displays XML-fed text advertisements. |
|---|
| 4 | * |
|---|
| 5 | * @author Jeroen Wijering |
|---|
| 6 | * @version 1.0 |
|---|
| 7 | **/ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | import com.jeroenwijering.players.*; |
|---|
| 11 | import com.jeroenwijering.utils.*; |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | class com.jeroenwijering.players.MidrollView extends AbstractView { |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | /** Prefix for the midroll XML **/ |
|---|
| 18 | private var prefix = "http://www.ltassrv.com/midroll/config.asp?cid="; |
|---|
| 19 | /** Reference to the XML parser. **/ |
|---|
| 20 | private var parser:XMLParser; |
|---|
| 21 | /** Reference to the image loader. **/ |
|---|
| 22 | private var loader:ImageLoader; |
|---|
| 23 | /** A list with all the configuration parameters. **/ |
|---|
| 24 | private var adconfig:Object; |
|---|
| 25 | /** A list with all the advertisements. **/ |
|---|
| 26 | private var advertisements:Array; |
|---|
| 27 | /** A reference to the midroll clip **/ |
|---|
| 28 | private var clip:MovieClip; |
|---|
| 29 | /** Currently active ad **/ |
|---|
| 30 | private var currentAd:Number; |
|---|
| 31 | /** Current playback time. **/ |
|---|
| 32 | private var currentTime:Number; |
|---|
| 33 | /** Current playback state **/ |
|---|
| 34 | private var currentState:Number; |
|---|
| 35 | /** Ad showing interval delay **/ |
|---|
| 36 | private var interval:Number; |
|---|
| 37 | /** Hae we rotated though all ads? **/ |
|---|
| 38 | private var rotated:Boolean; |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | /** Constructor; loads the ads and sets up the display **/ |
|---|
| 42 | function MidrollView(ctr:AbstractController,cfg:Object,fed:Object) { |
|---|
| 43 | super(ctr,cfg,fed); |
|---|
| 44 | var ref = this; |
|---|
| 45 | clip = config['clip'].midroll; |
|---|
| 46 | clip._visible = false; |
|---|
| 47 | parser = new XMLParser(); |
|---|
| 48 | parser.onComplete = function() { |
|---|
| 49 | ref.saveConfig(this.output['childs'][0]); |
|---|
| 50 | ref.saveAds(this.output['childs'][1]); |
|---|
| 51 | }; |
|---|
| 52 | trace(prefix+config['midroll']); |
|---|
| 53 | parser.parse(prefix+config['midroll']); |
|---|
| 54 | loader = new ImageLoader(clip.ovl.img.img,'false',50,50); |
|---|
| 55 | loader.onLoadFinished = function() { |
|---|
| 56 | Animations.fadeIn(ref.clip.ovl.img.img); |
|---|
| 57 | }; |
|---|
| 58 | Stage.addListener(this); |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /** Save the configuration options. **/ |
|---|
| 63 | function saveConfig(cfg:Object) { |
|---|
| 64 | adconfig = new Object(); |
|---|
| 65 | for (var i=0; i<cfg['childs'].length; i++) { |
|---|
| 66 | adconfig[cfg['childs'][i]['name']] = cfg['childs'][i]['value']; |
|---|
| 67 | } |
|---|
| 68 | if(config['lightcolor'] != '0x000000') { |
|---|
| 69 | adconfig['mouseover_color'] = config['lightcolor']; |
|---|
| 70 | adconfig['mouseover_extras'] = config['lightcolor']; |
|---|
| 71 | } |
|---|
| 72 | setColorsClicks(); |
|---|
| 73 | setDimensions(); |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | /** Save the ads to an array. **/ |
|---|
| 78 | function saveAds(ads:Object) { |
|---|
| 79 | advertisements = new Array(); |
|---|
| 80 | for (var i=0; i<ads['childs'].length; i++) { |
|---|
| 81 | var obj = new Object(); |
|---|
| 82 | for (var j=0; j < ads['childs'][i]['childs'].length; j++) { |
|---|
| 83 | obj[ads['childs'][i]['childs'][j]['name']] = |
|---|
| 84 | ads['childs'][i]['childs'][j]['value']; |
|---|
| 85 | } |
|---|
| 86 | advertisements.push(obj); |
|---|
| 87 | } |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | /** Setup the colors and clicks of the ad overlay. **/ |
|---|
| 92 | function setColorsClicks() { |
|---|
| 93 | var ref = this; |
|---|
| 94 | clip.btn.bck._alpha = adconfig['opacity']; |
|---|
| 95 | clip.btn.bck.col = new Color(clip.btn.bck); |
|---|
| 96 | clip.btn.bck.col.setRGB(adconfig['background_color']); |
|---|
| 97 | clip.btn.lne.col = new Color(clip.btn.lne); |
|---|
| 98 | clip.btn.lne.col.setRGB(adconfig['textcolor_description']); |
|---|
| 99 | clip.btn.onRollOver = function() { |
|---|
| 100 | this.lne.col.setRGB(ref.adconfig['mouseover_extras']); |
|---|
| 101 | }; |
|---|
| 102 | clip.btn.onRollOut = function() { |
|---|
| 103 | this.lne.col.setRGB(ref.adconfig['textcolor_description']); |
|---|
| 104 | }; |
|---|
| 105 | clip.btn.onRelease = function() { |
|---|
| 106 | ref.showMidroll(true); |
|---|
| 107 | }; |
|---|
| 108 | clip.ovl.setMask(clip.msk); |
|---|
| 109 | clip.ovl.bck._alpha = adconfig['opacity']; |
|---|
| 110 | clip.ovl.bck.col = new Color(clip.ovl.bck); |
|---|
| 111 | clip.ovl.bck.col.setRGB(adconfig['background_color']); |
|---|
| 112 | clip.ovl.bck.onRelease = function() {}; |
|---|
| 113 | clip.ovl.bck.useHandCursor = false; |
|---|
| 114 | clip.ovl.cls.col = new Color(clip.ovl.cls); |
|---|
| 115 | clip.ovl.cls.col.setRGB(adconfig['textcolor_description']); |
|---|
| 116 | clip.ovl.cls.onRollOver = function() { |
|---|
| 117 | this.col.setRGB(ref.adconfig['mouseover_extras']); |
|---|
| 118 | }; |
|---|
| 119 | clip.ovl.cls.onRollOut = function() { |
|---|
| 120 | this.col.setRGB(ref.adconfig['textcolor_description']); |
|---|
| 121 | }; |
|---|
| 122 | clip.ovl.cls.onRelease = function() { ref.hideMidroll(); }; |
|---|
| 123 | clip.ovl.abt.tf.text = adconfig['about_txt']; |
|---|
| 124 | clip.ovl.abt.col = new Color(clip.ovl.abt); |
|---|
| 125 | clip.ovl.abt.col.setRGB(adconfig['textcolor_description']); |
|---|
| 126 | clip.ovl.abt.onRollOver = function() { |
|---|
| 127 | this.col.setRGB(ref.adconfig['mouseover_extras']); |
|---|
| 128 | }; |
|---|
| 129 | clip.ovl.abt.onRollOut = function() { |
|---|
| 130 | this.col.setRGB(ref.adconfig['textcolor_description']); |
|---|
| 131 | }; |
|---|
| 132 | clip.ovl.abt.onRelease = function() { |
|---|
| 133 | getURL(ref.adconfig['about_url'],ref.config['linktarget']); |
|---|
| 134 | }; |
|---|
| 135 | clip.ovl.prv.col = new Color(clip.ovl.prv); |
|---|
| 136 | clip.ovl.prv.col.setRGB(adconfig['textcolor_description']); |
|---|
| 137 | clip.ovl.prv.onRollOver = function() { |
|---|
| 138 | this.col.setRGB(ref.adconfig['mouseover_extras']); |
|---|
| 139 | }; |
|---|
| 140 | clip.ovl.prv.onRollOut = function() { |
|---|
| 141 | this.col.setRGB(ref.adconfig['textcolor_description']); |
|---|
| 142 | }; |
|---|
| 143 | clip.ovl.prv.onRelease = function() { |
|---|
| 144 | if(ref.currentAd == 0) { |
|---|
| 145 | ref.setAd(ref.advertisements.length-1,true); |
|---|
| 146 | } else { |
|---|
| 147 | ref.setAd(ref.currentAd-1,true); |
|---|
| 148 | } |
|---|
| 149 | }; |
|---|
| 150 | clip.ovl.nxt.col = new Color(clip.ovl.nxt); |
|---|
| 151 | clip.ovl.nxt.col.setRGB(adconfig['textcolor_description']); |
|---|
| 152 | clip.ovl.nxt.onRollOver = function() { |
|---|
| 153 | this.col.setRGB(ref.adconfig['mouseover_extras']); |
|---|
| 154 | }; |
|---|
| 155 | clip.ovl.nxt.onRollOut = function() { |
|---|
| 156 | this.col.setRGB(ref.adconfig['textcolor_description']); |
|---|
| 157 | }; |
|---|
| 158 | clip.ovl.nxt.onRelease = function() { |
|---|
| 159 | if(ref.currentAd == ref.advertisements.length-1) { |
|---|
| 160 | ref.setAd(0,true); |
|---|
| 161 | } else { |
|---|
| 162 | ref.setAd(ref.currentAd+1,true); |
|---|
| 163 | } |
|---|
| 164 | }; |
|---|
| 165 | clip.ovl.img.col = new Color(clip.ovl.img.lne); |
|---|
| 166 | clip.ovl.img.col.setRGB(adconfig['textcolor_description']); |
|---|
| 167 | clip.ovl.tit.col = new Color(clip.ovl.tit); |
|---|
| 168 | clip.ovl.tit.col.setRGB(adconfig['textcolor_title']); |
|---|
| 169 | clip.ovl.tit.tf.autoSize = "left"; |
|---|
| 170 | clip.ovl.dsc.col = new Color(clip.ovl.dsc); |
|---|
| 171 | clip.ovl.dsc.col.setRGB(adconfig['textcolor_description']); |
|---|
| 172 | clip.ovl.dsc.tf.autoSize = "left"; |
|---|
| 173 | clip.ovl.lnk.col = new Color(clip.ovl.lnk); |
|---|
| 174 | clip.ovl.lnk.col.setRGB(adconfig['textcolor_link']); |
|---|
| 175 | clip.ovl.lnk.tf.textColor = adconfig['textcolor_link']; |
|---|
| 176 | clip.ovl.lnk.tf.autoSize = "left"; |
|---|
| 177 | clip.ovl.hit.onRollOver = function() { ref.overAd(); }; |
|---|
| 178 | clip.ovl.hit.onRollOut = function() { ref.outAd(); }; |
|---|
| 179 | clip.ovl.hit.onRelease = function() { ref.visitAd(); }; |
|---|
| 180 | }; |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | /** Setup dimensions of the players. **/ |
|---|
| 184 | function setDimensions() { |
|---|
| 185 | var stw = config['displaywidth']; |
|---|
| 186 | var sth = config['displayheight']; |
|---|
| 187 | if(Stage["displayState"] == "fullScreen") { |
|---|
| 188 | stw = Stage.width; |
|---|
| 189 | sth = Stage.height; |
|---|
| 190 | } |
|---|
| 191 | clip._y = sth-70; |
|---|
| 192 | clip.btn._x = stw-45; |
|---|
| 193 | if(clip.btn._y < 48) { clip.btn._y = 48 - sth; } |
|---|
| 194 | clip.msk._width = stw; |
|---|
| 195 | clip.ovl.bck._width = stw; |
|---|
| 196 | clip.ovl.lne._width = stw; |
|---|
| 197 | clip.ovl.hit._width = stw-20; |
|---|
| 198 | clip.ovl.cls._x = stw-60; |
|---|
| 199 | clip.ovl.abt._x = stw-145; |
|---|
| 200 | clip.ovl.prv._x = stw-26; |
|---|
| 201 | clip.ovl.nxt._x = stw; |
|---|
| 202 | }; |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | /** Show the midroll **/ |
|---|
| 206 | function showMidroll(man:Boolean) { |
|---|
| 207 | clip._visible = true; |
|---|
| 208 | clip.ovl._y = 70; |
|---|
| 209 | Animations.easeTo(clip.btn,clip.btn._x,48-Stage.height); |
|---|
| 210 | Animations.easeTo(clip.ovl,0,0); |
|---|
| 211 | interval = setInterval(this,'setAd',200,currentAd,man); |
|---|
| 212 | }; |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | /** Show the midroll **/ |
|---|
| 216 | function hideMidroll() { |
|---|
| 217 | clearInterval(interval); |
|---|
| 218 | Animations.easeTo(clip.btn,clip.btn._x,48); |
|---|
| 219 | Animations.easeTo(clip.ovl,0,70); |
|---|
| 220 | clip.ovl.tit.tf.text = ""; |
|---|
| 221 | clip.ovl.dsc.tf.text = ""; |
|---|
| 222 | clip.ovl.lnk.tf.text = ""; |
|---|
| 223 | clip.ovl.img.img._alpha = 0; |
|---|
| 224 | }; |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | /** Roll over the ad **/ |
|---|
| 228 | private function overAd() { |
|---|
| 229 | clip.ovl.img.col.setRGB(adconfig['mouseover_color']); |
|---|
| 230 | clip.ovl.tit.col.setRGB(adconfig['mouseover_color']); |
|---|
| 231 | clip.ovl.dsc.col.setRGB(adconfig['mouseover_color']); |
|---|
| 232 | clip.ovl.lnk.col.setRGB(adconfig['mouseover_color']); |
|---|
| 233 | }; |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | /** Roll over the ad **/ |
|---|
| 237 | private function outAd() { |
|---|
| 238 | clip.ovl.img.col.setRGB(adconfig['textcolor_description']); |
|---|
| 239 | clip.ovl.tit.col.setRGB(adconfig['textcolor_title']); |
|---|
| 240 | clip.ovl.dsc.col.setRGB(adconfig['textcolor_description']); |
|---|
| 241 | clip.ovl.lnk.col.setRGB(adconfig['textcolor_link']); |
|---|
| 242 | }; |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | /** Jump to the ad url **/ |
|---|
| 246 | private function visitAd() { |
|---|
| 247 | outAd(); |
|---|
| 248 | if(currentState > 0) { sendEvent('playpause'); } |
|---|
| 249 | getURL(advertisements[currentAd]['click_url'],'_blank'); |
|---|
| 250 | }; |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | /** Change the height to reflect the volume **/ |
|---|
| 254 | private function setTime(elp:Number) { |
|---|
| 255 | if(elp > adconfig['initial_delay'] && currentAd == undefined) { |
|---|
| 256 | currentAd = 0; |
|---|
| 257 | showMidroll(); |
|---|
| 258 | } |
|---|
| 259 | }; |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | /** Set a specific ad in the midroll **/ |
|---|
| 263 | private function setAd(idx:Number,man:Boolean) { |
|---|
| 264 | if(advertisements[idx]['image'].length > 10) { |
|---|
| 265 | clip.ovl.tit._x = clip.ovl.dsc._x = clip.ovl.lnk._x = 68; |
|---|
| 266 | clip.ovl.img._visible = true; |
|---|
| 267 | loader.loadImage(advertisements[idx]['image']); |
|---|
| 268 | clip.ovl.dsc.tf._width = clip.ovl.bck._width - 120; |
|---|
| 269 | } else { |
|---|
| 270 | clip.ovl.tit._x = clip.ovl.dsc._x = clip.ovl.lnk._x = 8; |
|---|
| 271 | clip.ovl.img.img._alpha = 0; |
|---|
| 272 | clip.ovl.img._visible = false; |
|---|
| 273 | clip.ovl.dsc.tf._width = clip.ovl.bck._width - 60; |
|---|
| 274 | } |
|---|
| 275 | var num = Math.round((clip.ovl.bck._width - clip.ovl.dsc._x)/6); |
|---|
| 276 | var dsc = StringMagic.chopString(advertisements[idx]['description'],num,1); |
|---|
| 277 | if( dsc != advertisements[idx]['description']) { dsc += ' ..'; } |
|---|
| 278 | Animations.easeText(clip.ovl.tit,advertisements[idx]['title']); |
|---|
| 279 | Animations.easeText(clip.ovl.dsc,dsc); |
|---|
| 280 | Animations.easeText(clip.ovl.lnk,advertisements[idx]['display_url']); |
|---|
| 281 | currentAd = idx; |
|---|
| 282 | clearInterval(interval); |
|---|
| 283 | if (rotated == true && man != true) { |
|---|
| 284 | rotated = false; |
|---|
| 285 | hideMidroll(); |
|---|
| 286 | idx = 0; |
|---|
| 287 | return; |
|---|
| 288 | } else if(currentAd == advertisements.length-1) { |
|---|
| 289 | if (man != true) { |
|---|
| 290 | rotated = true; |
|---|
| 291 | } |
|---|
| 292 | idx = 0; |
|---|
| 293 | } else { |
|---|
| 294 | idx++; |
|---|
| 295 | } |
|---|
| 296 | interval = setInterval(this,'setAd',adconfig['display_duration']*1000,idx); |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | /** Only display the eq if a song is playing **/ |
|---|
| 301 | private function setState(stt:Number) { |
|---|
| 302 | currentState = stt; |
|---|
| 303 | if(stt == 3) { |
|---|
| 304 | hideMidroll(); |
|---|
| 305 | } |
|---|
| 306 | }; |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | /** Catches stage resizing **/ |
|---|
| 310 | public function onResize() { setDimensions(); }; |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | /** Catches fullscreen escape **/ |
|---|
| 314 | public function onFullScreen(fs:Boolean) { |
|---|
| 315 | if(fs == false) { setDimensions(); } |
|---|
| 316 | }; |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | }; |
|---|