00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 import amg.*;
00014
00015
00016 class amg.Directory extends MovieClip{
00017 private var mcDebugWindow:MovieClip;
00018 private var mcDirectoryTitle:MovieClip;
00019 private var mcWelcomeMessage:MovieClip;
00020 private var mcCollectionBg:MovieClip;
00021 private var mcCollectionArea:MovieClip;
00022 private var _iHiddenCollectionArea:Number;
00023 private var mcScrollBar:MovieClip;
00024 private var mcBottomBar:MovieClip;
00025 private var mcFooterText:MovieClip;
00026 private var _mcCollectionAreaMask:MovieClip;
00027 private var _iImageAreaMaskDepth:Number = 6000;
00028 private var _debugWindow:Boolean = false;
00029 private var _iDebugWindowDepth:Number = 3000;
00030
00031
00032 private var _iCollectionAreaTopSpacer:Number = 19;
00033 private var _iCollectionClipWidth:Number = 224;
00034 private var _iCollectionClipHeight:Number = 137;
00035 private var _iCollectionClipRightMargin:Number = 10;
00036 private var _iCollectionClipTopMargin:Number = 10;
00037
00038 private var _iControlsStartDepth = 1;
00039
00040 private var _iTotalRows:Number;
00041 private var _iCollectionRowHeight:Number;
00042 private var _iCollectionsPerRow:Number
00043 private var _iScrollPosition:Number
00044
00045 private var _oStageListener:Object;
00046 private var _oKeyListener:Object;
00047
00048 private var _strCollectionSetUrl:String;
00049 private var _xmlDirectory:XML;
00050 private var _iCollectionClipsDepth = 1000;
00051 private var _aCollectionClips:Array;
00052
00053
00054
00055
00056
00057 public function Directory(){
00058
00059
00060 if (_debugWindow) {
00061 this.mcDebugWindow = this.attachMovie("mcDebugWindow", "debug", _iDebugWindowDepth, {_y:10});
00062 }
00063
00064
00065 mcDirectoryTitle.swapDepths(_iControlsStartDepth++);
00066 mcWelcomeMessage.swapDepths(_iControlsStartDepth++);
00067 mcCollectionBg.swapDepths(_iControlsStartDepth++);
00068 mcCollectionArea.swapDepths(_iControlsStartDepth++);
00069 mcScrollBar.swapDepths(_iControlsStartDepth++);
00070 mcScrollBar._visible = false;
00071 mcBottomBar.swapDepths(_iControlsStartDepth++);
00072 mcFooterText.swapDepths(_iControlsStartDepth++);
00073
00074
00075 _xmlDirectory = new XML();
00076 _xmlDirectory.ignoreWhite = true;
00077
00078
00079 _oStageListener = new Object();
00080 _oStageListener._parent = this;
00081 Stage.scaleMode = "noScale";
00082 Stage.align = "TL";
00083 Stage.addListener(_oStageListener);
00084 _oStageListener.onResize = resizeStage;
00085 _oStageListener.onResize();
00086
00087
00088 _oKeyListener = new Object();
00089 _oKeyListener._parent = this;
00090 _oKeyListener.onKeyDown = keyboardControls;
00091 Key.addListener(_oKeyListener);
00092 }
00093
00094 public function initShow(collectionSet:String):Void{
00095
00096
00097 if(collectionSet == "localtest"){
00098 writeDebug("initing localtest");
00099 this._strCollectionSetUrl = "../data/testDirectory.xml";
00100 }
00101 else{
00102 writeDebug("loading collection " + collectionSet,"main");
00103 this._strCollectionSetUrl = collectionSet;
00104 }
00105 this.loadXML(this._strCollectionSetUrl);
00106
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 private function loadXML(xmlUrl:String):Void {
00118
00119 var me:Object = this;
00120 this._xmlDirectory.onLoad = function(success:Boolean) {
00121 if (success) {
00122 me.parseDirectoryXML();;
00123 }
00124 else {
00125
00126 }
00127 };
00128
00129 _xmlDirectory.load(xmlUrl);
00130
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 private function parseDirectoryXML():Void {
00140
00141
00142 this._aCollectionClips = new Array();
00143
00144
00145 var xmlRootNode = _xmlDirectory.firstChild;
00146
00147
00148 var xmlHead:XMLNode = xmlRootNode.firstChild;
00149 var xmlSiteTitle:XMLNode = xmlHead.firstChild;
00150 var xmlWelcome:XMLNode = xmlSiteTitle.nextSibling;
00151 var xmlContact:XMLNode = xmlWelcome.nextSibling;
00152
00153
00154 this.mcDirectoryTitle.txtTitle.text = xmlSiteTitle.firstChild;
00155 this.mcWelcomeMessage.txtWelcome.text = xmlWelcome.firstChild;
00156 this.mcFooterText.txtContact.text = xmlContact.firstChild;
00157
00158
00159
00160 var xmlCollections:XMLNode = xmlHead.nextSibling;
00161
00162 if(xmlCollections.firstChild){
00163 var xmlCollection:XMLNode = xmlCollections.firstChild;
00164
00165
00166 while (xmlCollection) {
00167
00168
00169 var oCollectionClip:MovieClip = this.mcCollectionArea.attachMovie("mcCollectionClip","collClip"+_aCollectionClips.length,_iCollectionClipsDepth+_aCollectionClips.length);
00170 oCollectionClip.initClip(xmlCollection.attributes.collectionName,xmlCollection.attributes.collectionTitle,xmlCollection.attributes.thumb,xmlCollection.attributes.description,xmlCollection.attributes.numImages);
00171
00172 _aCollectionClips.push(oCollectionClip);
00173 xmlCollection = xmlCollection.nextSibling;
00174 }
00175
00176 this._oStageListener.onResize();
00177 }
00178
00179
00180 }
00181
00182 private function keyboardControls(){
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221 private function resizeStage():Void{
00222 var screenWidth:Number = Stage.width;
00223 var screenHeight:Number = Stage.height;
00224
00225 if (screenWidth<400) {
00226 return;
00227 }
00228
00229 this._parent.mcTopBar._width = screenWidth;
00230 this._parent.mcCollectionBg._width = screenWidth - 20;
00231
00232
00233 if(this._parent._aCollectionClips){
00234
00235 this._parent.scrollCollections(0);
00236 this._parent.mcScrollBar.reset();
00237
00238 var iTotalClipWidth:Number = this._parent._iCollectionClipWidth + this._parent._iCollectionClipRightMargin;
00239 this._parent._iCollectionsPerRow = Math.floor((this._parent.mcCollectionBg._width - 23) / iTotalClipWidth);
00240 this._parent._iTotalRows = Math.ceil(this._parent._aCollectionClips.length/this._parent._iCollectionsPerRow);
00241 this._parent._iCollectionRowHeight = this._parent._iCollectionClipHeight + this._parent._iCollectionClipTopMargin;
00242 var iRowsShown = Math.floor(((screenHeight*.9)-this._parent.mcCollectionBg._y)/this._parent._iCollectionRowHeight);
00243 var iMaskHeight = (iRowsShown*this._parent._iCollectionRowHeight)+this._parent._iCollectionAreaTopSpacer;
00244 if(this._parent._iTotalRows > iRowsShown){
00245 this._parent._iHiddenCollectionArea = (this._parent._iTotalRows-iRowsShown) * this._parent._iCollectionRowHeight;
00246 this._parent.mcScrollBar._x = screenWidth - 38;
00247 this._parent.mcScrollBar.mcScrollBarMiddle._height = (iRowsShown*this._parent._iCollectionRowHeight)-(this._parent._iCollectionClipTopMargin+20);
00248 this._parent.mcScrollBar.mcScrollBarBottom._y = this._parent.mcScrollBar.mcScrollBarMiddle._y + this._parent.mcScrollBar.mcScrollBarMiddle._height;
00249 this._parent.mcScrollBar._visible = true;
00250 }
00251 else{
00252 this._parent.mcScrollBar._visible = false;
00253 }
00254 this._parent.mcBottomBar._width = screenWidth;
00255 this._parent.mcBottomBar._y = this._parent.mcCollectionBg._y + iMaskHeight;
00256 this._parent.mcFooterText._y = this._parent.mcBottomBar._y;
00257 this._parent.createMask(this._parent.mcCollectionBg._x,this._parent.mcCollectionBg._y+2,this._parent.mcCollectionBg._width,iMaskHeight-2,this._parent.mcCollectionArea);
00258
00259
00260 this._parent.arrangeClips();
00261 }
00262
00263 }
00264
00265 private function arrangeClips(Void):Void{
00266
00267
00268 var iTotalClipWidth:Number = _iCollectionClipWidth + _iCollectionClipRightMargin;
00269 _iCollectionsPerRow = Math.floor((mcCollectionBg._width - 23) / iTotalClipWidth);
00270
00271 var iCollectionRowWidth = (iTotalClipWidth*_iCollectionsPerRow)- (_iCollectionClipRightMargin);
00272 var iCollectionOffset = 10 + (((mcCollectionBg._width-23) - iCollectionRowWidth)/2);
00273
00274 for(var i:Number=0;i<_aCollectionClips.length;i++){
00275 _aCollectionClips[i]._y = mcCollectionBg._y + _iCollectionAreaTopSpacer + ((_iCollectionClipHeight+10) * (Math.ceil(((i+1)/_iCollectionsPerRow))-1)) ;
00276 _aCollectionClips[i]._x = iCollectionOffset + ((iTotalClipWidth) * ((i)%_iCollectionsPerRow));
00277 }
00278
00279 }
00280
00281 public function scrollCollections(scrollAmount:Number):Void{
00282 this.mcCollectionArea._y = _iHiddenCollectionArea * (-1*scrollAmount);
00283 this._iScrollPosition = scrollAmount * _aCollectionClips.length;
00284 }
00285
00286 private function createMask(startX:Number,startY:Number,width:Number,height:Number,clip:MovieClip):Void{
00287 _mcCollectionAreaMask = this.createEmptyMovieClip("mask",_iImageAreaMaskDepth);
00288 _mcCollectionAreaMask.beginFill(0x000000);
00289 _mcCollectionAreaMask.moveTo(startX,startY);
00290 _mcCollectionAreaMask.lineTo(startX + width,startY);
00291 _mcCollectionAreaMask.lineTo(startX + width,startY + height);
00292 _mcCollectionAreaMask.lineTo(startX,startY + height);
00293 _mcCollectionAreaMask.moveTo(startX,startY);
00294 _mcCollectionAreaMask.endFill();
00295 clip.setMask(_mcCollectionAreaMask);
00296 }
00297
00298 private function clearMask(clip:MovieClip){
00299 clip.setMask(null);
00300 this._mcCollectionAreaMask.clear();
00301
00302 }
00303
00304 private function writeDebug(debugOut:String, area:String):Void {
00305 switch (area) {
00306 case "main" :
00307 this.mcDebugWindow.main.text += debugOut+newline;
00308 break;
00309 case "status" :
00310 this.mcDebugWindow.status.text = debugOut;
00311 break;
00312 case "time" :
00313 this.mcDebugWindow.time.text = debugOut;
00314 break;
00315 }
00316 }
00317 private function openDebug() {
00318 this.mcDebugWindow = this.attachMovie("mcDebugWindow", "debug", _iDebugWindowDepth, {_y:10});
00319 this._debugWindow = true;
00320 }
00321
00322
00323 }