My favorites | Sign in
Project Logo
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
*
* MIT License
*
* Copyright (c) 2008, Juan Delgado - Zarate
*
* http://zarate.tv/projects/zcode/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

import tv.zarate.utils.TextfieldUtils;
import tv.zarate.utils.MovieclipUtils;
import tv.zarate.utils.Delegate;

import tv.zarate.application.View;

import tv.zarate.projects.zplayer.zpModel;
import tv.zarate.projects.zplayer.zpConstants;
import tv.zarate.projects.zplayer.Item;
import tv.zarate.projects.zplayer.Player;
import tv.zarate.projects.zplayer.PlayerVideo;
import tv.zarate.projects.zplayer.PlayerImage;
import tv.zarate.projects.zplayer.ItemsBand;
import tv.zarate.projects.zplayer.InfoBand;
import tv.zarate.projects.zplayer.zpImage;

class tv.zarate.projects.zplayer.zpView extends View{

private var model:zpModel;
private var currentPlayer:Player;
private var itemsBand:ItemsBand;
private var infoBand:InfoBand;

private var view_mc:MovieClip;
private var title_mc:MovieClip;
private var player_mc:MovieClip;
private var background_mc:MovieClip;
private var items_mc:MovieClip;

private var margin:Number = 1;
private var titleMargin:Number = 10;
private var maxWidth:Number = 0;
private var playerWidth:Number = 0;
private var playerHeight:Number = 0;
private var itemsBandHeight:Number = 0;
private var showItemsBand:Boolean = false;
private var selectItemCallback:Function;

private var BACKGROUND_DEPTH:Number = 50;
private var TITLE_DEPTH:Number = 100;
private var PLAYER_DEPTH:Number = 200;
private var INFO_DEPTH:Number = 300;
private var ITEMS_DEPTH:Number = 400;

public function zpView(){

super();

}

public function zpConf(_selectItemCallback:Function):Void{

selectItemCallback = _selectItemCallback;

showItemsBand = (model.items.length > 1);
itemsBandHeight = (showItemsBand)? 110:0;

if(showItemsBand){

showItems();

}

layout();

}

public function showItem(item:Item,finishCallback:Function):Void{

if(currentPlayer != null){

currentPlayer.remove();
infoBand.remove();

}

updateTitle(item.title);

player_mc = view_mc.createEmptyMovieClip("player_mc",PLAYER_DEPTH);
player_mc._x = margin;
player_mc._y = title_mc._y + title_mc._height + margin;

playerHeight = height - player_mc._y - itemsBandHeight - margin;

switch(item.type){

case(zpConstants.TYPE_VIDEO):
currentPlayer = new PlayerVideo(item,player_mc,finishCallback); break;

case(zpConstants.TYPE_IMAGE):
currentPlayer = new PlayerImage(item,player_mc,finishCallback); break;

}

itemsBand.setCurrentItem(item);

currentPlayer.setSize(playerWidth,playerHeight);
currentPlayer.playItem();

if(item.info != ""){

var info_mc:MovieClip = view_mc.createEmptyMovieClip("info_mc",INFO_DEPTH);
infoBand = new InfoBand(info_mc,width,item.info);

info_mc._y = player_mc._y + player_mc._height - info_mc._height;

if((item.type == zpConstants.TYPE_IMAGE && zpImage(item).sound != undefined) || item.type == zpConstants.TYPE_VIDEO){ info_mc._y -= zpConstants.LOAD_BAR_HEIGHT; }

}

}

// **************** PRIVATE METHODS ****************

private function initialLayout():Void{

// this method is called just once
// width and height are NOT ready at this
// point

background_mc = view_mc.createEmptyMovieClip("background_mc",BACKGROUND_DEPTH);
items_mc = view_mc.createEmptyMovieClip("items_mc",ITEMS_DEPTH);

title_mc = view_mc.createEmptyMovieClip("title_mc",TITLE_DEPTH);
title_mc._x = titleMargin;
title_mc._y = 5;

var titleBorder_mc:MovieClip = title_mc.createEmptyMovieClip("titleBorder_mc",200);

var field:TextField = TextfieldUtils.createField(title_mc,100,20,"none");
field.setNewTextFormat(new TextFormat("Verdana",12,0xffffff));

}

private function layout():Void{

// this method is called everytime
// the Stage is resized and *at least* once

maxWidth = width - margin * 2;
playerWidth = maxWidth;

title_mc.field._width = width - titleMargin * 2;

title_mc.titleBorder_mc._x = -titleMargin;
title_mc.titleBorder_mc._y = title_mc._height + 5;
MovieclipUtils.DrawSquare(title_mc.titleBorder_mc,0xffffff,100,width,1);

background_mc.clear();

MovieclipUtils.DrawRoundedSquare(background_mc,0x4f7ec4,100,width,height,10);

items_mc._x = margin;
items_mc._y = height - itemsBandHeight - margin;

itemsBand.setSize(maxWidth,itemsBandHeight);

}

private function showItems():Void{

var updateInfoCallback:Function = Delegate.create(this,updateInfo);
var toggleInfoCallback:Function = Delegate.create(this,toggleInfo);

itemsBand = new ItemsBand();
itemsBand.config(model.items,items_mc,selectItemCallback,updateInfoCallback,toggleInfoCallback);

}

private function toggleInfo():Void{
infoBand.toggleVisibility();
}

private function updateInfo(over:Boolean,txt:String):Void{

if(over){

infoBand.updateText(txt);

} else {

infoBand.resetText();

}

}

private function updateTitle(s:String):Void{
title_mc.field.text = s;
}

}
Show details Hide details

Change log

r120 by zzzarate on Aug 14, 2008   Diff
ZCode now released under MIT license.
Enjoy.
Go to: 
Project members, sign in to write a code review

Older revisions

r110 by zzzarate on May 10, 2008   Diff
In the middle of revamping the video
player a litte bit, just stay tunned.
r76 by zzzarate on Feb 18, 2008   Diff
Again, reordering namespace.
r75 by zzzarate on Feb 18, 2008   Diff
Namespace update, removed capital
letters. "Projects", "Utils" and
"Application" go to "projects",
"utils" and "application".

...
All revisions of this file

File info

Size: 6109 bytes, 220 lines

File properties

svn:executable
*
Hosted by Google Code