Adobe Systems, Inc.

Directory.as

Go to the documentation of this file.
00001 /****************************************
00002 ** Copyright 2005-2006 Adobe Systems Incorporated
00003 ** Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004 ** or a copy at http://opensource.adobe.com/licenses.html)
00005 **
00006 ** Directory Class 
00007 ** 
00008 ** This class is linked to the mcDirectory movieclip in 'directory.fla'
00009 ** It handles the parsing of the directory xml data,
00010 ** and creation of Collection objects
00011 *********************************************/
00012 //import other classes from this namespace
00013 import amg.*;
00014 
00015 //implements ISmartLoader interface insuring that the smartLoader method is present
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         //thumbnail area
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;                                          //xml object to hold directory XML file
00050         private var _iCollectionClipsDepth = 1000;
00051         private var _aCollectionClips:Array;                                    //array to hold ImageClip objects built from XML nodes
00052 
00053         
00054         /****************************************************
00055         ** Directory Class Constructor
00056         *****************************************************/
00057         public function Directory(){
00058                 
00059                 //debug window var is set from component 
00060                 if (_debugWindow) {
00061                         this.mcDebugWindow = this.attachMovie("mcDebugWindow", "debug", _iDebugWindowDepth, {_y:10});
00062                 }
00063                 
00064                 //since we have some stage instance mc's -we need to swap their depths so they can be 'over' dynamic clips 
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                 //init XML obj
00075                 _xmlDirectory = new XML();
00076                 _xmlDirectory.ignoreWhite = true;
00077                 
00078                 //set stage listener to resize the show elements when stage is resized
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                 //add a keyboard listener for keyboard control of gallery
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                 //check flashvars for data passed from HTML file
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         ** loadXML
00111         ** This function loads the XML collection description file 
00112         ** The onLoad callback function allows the show to wait
00113         ** until the XML has completely loaded before stating the slideshow
00114         ** the callback does not have scope to this class however
00115         ** hence the local 'me' variable used to provide scope back to this class
00116         *************************************************************************/
00117         private function loadXML(xmlUrl:String):Void {
00118                 //set the callback for xml load event that references this class as 'me'
00119                 var me:Object = this;
00120                 this._xmlDirectory.onLoad = function(success:Boolean) {
00121                         if (success) {
00122                                 me.parseDirectoryXML();;
00123                         }
00124                         else {
00125                                 //error loading XML file
00126                         }
00127                 };
00128                 //load the SMIL file
00129                 _xmlDirectory.load(xmlUrl);
00130                 
00131         }
00132         
00133         /*********************************************************
00134         ** parseCollectionXML
00135         ** function to parse the collection XML file into
00136         ** the _aImageClips array, an associative array
00137         ** of ImageClip objects and start times
00138         **********************************************************/
00139         private function parseDirectoryXML():Void {
00140                 
00141                 //arrays to hold ImageClip and ThumbClip objects
00142                 this._aCollectionClips = new Array();
00143                 
00144                 //root node
00145                 var xmlRootNode = _xmlDirectory.firstChild;
00146                 
00147                 //header nodes
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                 //set values based on head nodes
00154                 this.mcDirectoryTitle.txtTitle.text = xmlSiteTitle.firstChild;
00155                 this.mcWelcomeMessage.txtWelcome.text = xmlWelcome.firstChild;
00156                 this.mcFooterText.txtContact.text = xmlContact.firstChild;
00157                 
00158 
00159                 //photo nodes
00160                 var xmlCollections:XMLNode = xmlHead.nextSibling;
00161                 
00162                 if(xmlCollections.firstChild){
00163                         var xmlCollection:XMLNode = xmlCollections.firstChild;
00164         
00165                         //parse out all colection nodes and create CollectionClip objects
00166                         while (xmlCollection) {
00167                                 
00168                                 //create a new collection clip
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                                 //add it to the array
00172                                 _aCollectionClips.push(oCollectionClip);
00173                                 xmlCollection = xmlCollection.nextSibling;
00174                         }
00175                         //calculate where collection  clips should be placed on the stage
00176                         this._oStageListener.onResize();
00177                 }
00178                 
00179                 
00180         }
00181         
00182         private function keyboardControls(){
00183                 //NOTE: this function is meant to be called from a Listener Object
00184                 //--which does not have direct scope into this class' properties
00185                 //the _parent prop is explicitly set in the constructor of the class
00186                 //so _parent in this case refers to the class itself
00187                 
00188                 /*
00189                 if(Key.getCode() == Key.RIGHT)
00190                         _parent.vcrControls("forward");
00191                 if(Key.getCode() == Key.LEFT)
00192                         _parent.vcrControls("back");
00193                 if(Key.getCode() == Key.UP)
00194                         _parent.vcrControls("first");
00195                 if(Key.getCode() == Key.DOWN)
00196                         _parent.vcrControls("last");
00197                 if(Key.getCode() == Key.SPACE){
00198                         if(_parent._strPlayMode == "Paused"){
00199                                 _parent.mcBottomControlsCenter.mcVCRControls.mcPausePlay.gotoAndStop(1);
00200                                 _parent.vcrControls("play");
00201                         }
00202                         else if(_parent._strPlayMode == "Playing"){
00203                                 _parent.mcBottomControlsCenter.mcVCRControls.mcPausePlay.gotoAndStop(2);
00204                                 _parent.vcrControls("pause");
00205                         }
00206                 }
00207                 if(Key.getCode() == Key.CONTROL){
00208                         trace("control key");
00209                 }
00210                 */
00211                 
00212         }
00213         
00214         /**************************************************************
00215         ** RESIZESTAGE
00216         ** NOTE: this function is called from a Stage Listener Object
00217         ** which does not have direct scope into this class' properties
00218         ** so, the listener's '_parent' property is explicitly set to this
00219         ** class itself when the stage listener is instantiated 
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                 //if the image clip array has been created
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                         //place thumbs and preview box on the stage based on its height/width
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 }

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.