| 1 | /** |
|---|
| 2 | * Thumbnailbar with recommended videos. |
|---|
| 3 | * |
|---|
| 4 | * @author Jeroen Wijering |
|---|
| 5 | * @version 1.0 |
|---|
| 6 | **/ |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | import com.jeroenwijering.utils.ImageLoader; |
|---|
| 10 | import com.jeroenwijering.utils.Animations; |
|---|
| 11 | import com.jeroenwijering.utils.XMLParser; |
|---|
| 12 | import com.jeroenwijering.players.AbstractController; |
|---|
| 13 | import com.jeroenwijering.players.AbstractView; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | class com.jeroenwijering.players.RecommendationsView extends AbstractView { |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /** reference to config Array **/ |
|---|
| 20 | private var config:Object; |
|---|
| 21 | /** reference to feed Array **/ |
|---|
| 22 | private var feeder:Object; |
|---|
| 23 | /** Reference to the movieclip **/ |
|---|
| 24 | private var clip:MovieClip; |
|---|
| 25 | /** XML parser reference **/ |
|---|
| 26 | private var parser:XMLParser; |
|---|
| 27 | /** Recommendations array **/ |
|---|
| 28 | private var recommendations:Array; |
|---|
| 29 | /** Current show offset **/ |
|---|
| 30 | private var offset:Number = 0; |
|---|
| 31 | /** Number of thumbs maximum on screen **/ |
|---|
| 32 | private var maximum:Number; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /** Constructor **/ |
|---|
| 37 | function RecommendationsView(ctr:AbstractController, |
|---|
| 38 | cfg:Object,fed:Object) { |
|---|
| 39 | config = cfg; |
|---|
| 40 | feeder = fed; |
|---|
| 41 | clip = config["clip"].recommendations; |
|---|
| 42 | var ref = this; |
|---|
| 43 | parser = new XMLParser(); |
|---|
| 44 | parser.onComplete = function() { |
|---|
| 45 | ref.loadRecommendations(this.output); |
|---|
| 46 | }; |
|---|
| 47 | Stage.addListener(this); |
|---|
| 48 | setButtons(); |
|---|
| 49 | }; |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | /** Set the colors, clicks and dimensions of the buttons. **/ |
|---|
| 53 | private function setButtons() { |
|---|
| 54 | var ref = this; |
|---|
| 55 | maximum = Math.floor((config['displaywidth']-44)/70); |
|---|
| 56 | clip._visible = false; |
|---|
| 57 | clip.txt._x = 10; |
|---|
| 58 | clip.txt._width = config['displaywidth'] -20; |
|---|
| 59 | clip.txt.textColor = config['backcolor']; |
|---|
| 60 | clip.prv._x = config['displaywidth']/2 - maximum*35; |
|---|
| 61 | clip.nxt._x = config['displaywidth']/2 + maximum*35; |
|---|
| 62 | clip.prv.col = new Color(clip.prv); |
|---|
| 63 | clip.prv.col.setRGB(config['backcolor']); |
|---|
| 64 | clip.prv.onRelease = function() { |
|---|
| 65 | this.col.setRGB(ref.config['backcolor']); |
|---|
| 66 | ref.showRecommendations(ref.offset - ref.maximum); |
|---|
| 67 | }; |
|---|
| 68 | clip.prv._visible = false; |
|---|
| 69 | clip.nxt.col = new Color(clip.nxt); |
|---|
| 70 | clip.nxt.col.setRGB(config['backcolor']); |
|---|
| 71 | clip.nxt.onRelease = function() { |
|---|
| 72 | this.col.setRGB(ref.config['backcolor']); |
|---|
| 73 | ref.showRecommendations(ref.offset + ref.maximum); |
|---|
| 74 | }; |
|---|
| 75 | clip.nxt._visible = false; |
|---|
| 76 | clip.itm._visible = false; |
|---|
| 77 | for(var i=0; i<maximum; i++) { |
|---|
| 78 | clip.itm.duplicateMovieClip('itm'+i,i); |
|---|
| 79 | clip['itm'+i]._x = clip.prv._x+i*70 + 5; |
|---|
| 80 | clip['itm'+i].ldr=new ImageLoader(clip['itm'+i].img,"true",60,45); |
|---|
| 81 | clip['itm'+i].ldr.onLoadFinished = function() { |
|---|
| 82 | Animations.fadeIn(this.targetClip._parent); |
|---|
| 83 | }; |
|---|
| 84 | clip['itm'+i].img.setMask(clip['itm'+i].msk); |
|---|
| 85 | clip['itm'+i].cl1 = new Color(clip['itm'+i].bdr); |
|---|
| 86 | clip['itm'+i].cl1.setRGB(config['frontcolor']); |
|---|
| 87 | clip['itm'+i].cl2 = new Color(clip['itm'+i].icn); |
|---|
| 88 | clip['itm'+i].cl2.setRGB(config['backcolor']); |
|---|
| 89 | clip['itm'+i].icn._visible = false; |
|---|
| 90 | clip['itm'+i].onRollOver = function() { |
|---|
| 91 | this.cl1.setRGB(ref.config['backcolor']); |
|---|
| 92 | this.icn._visible = true; |
|---|
| 93 | ref.setTitle(this.num); |
|---|
| 94 | }; |
|---|
| 95 | clip['itm'+i].onRollOut = function() { |
|---|
| 96 | this.cl1.setRGB(ref.config['frontcolor']); |
|---|
| 97 | this.icn._visible = false; |
|---|
| 98 | ref.clearTitle(); |
|---|
| 99 | }; |
|---|
| 100 | clip['itm'+i].onRelease = function() { |
|---|
| 101 | ref.getLink(this.num); |
|---|
| 102 | }; |
|---|
| 103 | clip['itm'+i]._visible = false; |
|---|
| 104 | clip['itm'+i]._alpha = 0; |
|---|
| 105 | } |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | /** Load the recommendations from XML **/ |
|---|
| 110 | private function loadRecommendations(rcm:Object) { |
|---|
| 111 | recommendations = new Array(); |
|---|
| 112 | for (var i=0; i<rcm['childs'].length; i++) { |
|---|
| 113 | var obj = new Object(); |
|---|
| 114 | for (var j=0; j < rcm['childs'][i]['childs'].length; j++) { |
|---|
| 115 | obj[rcm['childs'][i]['childs'][j]['name']] = |
|---|
| 116 | rcm['childs'][i]['childs'][j]['value']; |
|---|
| 117 | } |
|---|
| 118 | recommendations.push(obj); |
|---|
| 119 | } |
|---|
| 120 | if(recommendations.length < maximum) { |
|---|
| 121 | for(var i=0; i<recommendations.length; i++) { |
|---|
| 122 | clip['itm'+i]._x += 35*(maximum-recommendations.length); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | showRecommendations(0); |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | /** Show the recommendations on screen **/ |
|---|
| 130 | private function showRecommendations(off:Number) { |
|---|
| 131 | arguments.length == 1 ? offset = off: null; |
|---|
| 132 | offset == 0 ? clip.prv._visible = false: clip.prv._visible = true; |
|---|
| 133 | offset >= recommendations.length-maximum ? clip.nxt._visible = false: clip.nxt._visible = true; |
|---|
| 134 | for(var i=0; i<maximum; i++) { |
|---|
| 135 | clip['itm'+i].num = i+offset; |
|---|
| 136 | if(recommendations[i+offset] == undefined) { |
|---|
| 137 | clip['itm'+i]._visible = false; |
|---|
| 138 | clip['itm'+i]._alpha = 0; |
|---|
| 139 | } else { |
|---|
| 140 | clip['itm'+i].ldr.loadImage(recommendations[i+offset]['image']); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | if(Stage['displayState'] == "fullScreen") { |
|---|
| 144 | clip._x = Math.round(Stage.width/2 - clip._width/2)-10; |
|---|
| 145 | clip._y = Stage.height-165; |
|---|
| 146 | } else { |
|---|
| 147 | clip._x = Math.round(config['displaywidth']/2 - clip._width/2)-10; |
|---|
| 148 | clip._y = config['displayheight']-85; |
|---|
| 149 | } |
|---|
| 150 | }; |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | /** lower the list with related items **/ |
|---|
| 154 | private function setState(stt:Number) { |
|---|
| 155 | if(stt == 3) { |
|---|
| 156 | if(recommendations == undefined) { |
|---|
| 157 | parser.parse(config['recommendations']); |
|---|
| 158 | } else { |
|---|
| 159 | showRecommendations(); |
|---|
| 160 | } |
|---|
| 161 | clip._visible = true; |
|---|
| 162 | config['clip'].display.thumb._alpha = 33; |
|---|
| 163 | } else if (stt == 1 || stt == 2) { |
|---|
| 164 | clip._visible = false; |
|---|
| 165 | config['clip'].display.thumb._alpha = 100; |
|---|
| 166 | } |
|---|
| 167 | }; |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | /** Set the title of the rolled over thumb. **/ |
|---|
| 171 | private function setTitle(idx:Number) { |
|---|
| 172 | clip.txt.text = recommendations[idx]['title']; |
|---|
| 173 | }; |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | /** Clear the title field again. **/ |
|---|
| 177 | private function clearTitle() { |
|---|
| 178 | clip.txt.text = ""; |
|---|
| 179 | }; |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | /** Jump to the page with the requested file **/ |
|---|
| 183 | private function getLink(idx:Number) { |
|---|
| 184 | getURL(recommendations[idx]['link'],config['linktarget']); |
|---|
| 185 | }; |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | /** OnResize Handler: catches stage resizing. **/ |
|---|
| 189 | public function onResize() { |
|---|
| 190 | if(config['displayheight'] >= config["height"]) { |
|---|
| 191 | config["height"] = config["displayheight"] = Stage.height; |
|---|
| 192 | config["width"] = config["displaywidth"] = Stage.width; |
|---|
| 193 | } |
|---|
| 194 | showRecommendations(); |
|---|
| 195 | }; |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | /** Catches fullscreen escape. **/ |
|---|
| 199 | public function onFullScreen(fs:Boolean) { |
|---|
| 200 | showRecommendations(); |
|---|
| 201 | }; |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | } |
|---|