import main.PhotoModelFileSystem import main.PhotoControllerIcons class main.PhotoViewIcons extends mvc.AbstractView{ private var model:PhotoModelFileSystem; private var controller:PhotoControllerIcons; private var holder:Holder //holder for photos private var iconsP:Array = new Array() //array of icons private var cantIcons:Number //quantity of icons on stage private var totalPages:Number //total pages of icons private var hw:Number = 100 //size of icon private var t:MovieClip //timeline private var counter:Number=0 //counter for icons private var output:TextField private var dataLoaded:Boolean = false private var state:String = "single" //Could be single or icons /* * Constructor * @param m Model of this view * @param c Controller of this view * @param timeline Reference to the timeline holding this view */ public function PhotoViewIcons (m: PhotoModelFileSystem, c:PhotoControllerIcons, timeline:MovieClip) { // Set the model. setModel(m); t = timeline // If a controller was supplied, use it. Otherwise let the first // call to getController() create the default controller. if (c !== undefined) { setController(c); } } /* * Creates an array of positions for icons (rows and columns) * @ param row */ private function setupIcons(row:Number, col:Number):Boolean{ if(!dataLoaded) return false //outer loop for rows for(var r=0; r1) showPrev(); else hidePrev(); //Output text t.output.text = "Image " +pos + ": " + model.currentItem; break default: //trace("Nothing here!") } } /* * makeIcons creates Icons on stage * @param pos could be current, next or previous */ public function makeIcons (pos:String) : Void { var page = getPage() //calculate page if(pos!="current") page = (pos=="next")?page+=1 : page-=1 //Show or hide next and previous arrows if(Math.ceil(model.getCantItems()/cantIcons)==page) hideNext(); else showNext() if(page==1) hidePrev(); else showPrev() //First item of this page var first = ((page-1)*cantIcons)+1 model.currentItem = first var init:Number = model.getPos() var last:Number //resets counter counter = 0; //Hide single loader and big photo t.initHolder._visible = t.foto._visible = false last = ((init+iconsP.length)<=model.getCantItems())?init + (iconsP.length)-1 : model.getCantItems() t.output.text = first+" to "+last+" from "+model.getCantItems() showIcons() //Display photo numbers t.pag.displayNumbers(page) } //How many icons per page is holding this view public function getIconsPerPage():Number{ return cantIcons } //Show icons render the icons on Stage. It's called from the Holder class recursively until all icons finish to load private function showIcons () : Void { var init:Number = model.getPos() if(counter0)?Math.ceil(init/cantIcons) : Math.floor(init/cantIcons) //Fix zero on first page if(page==0) page = 1 return page } //Clear icons on stage public function clearStage():Void{ //Clear icons on stage var last:Number = counter+cantIcons //copy to clip timeline and make a reference t.counter=0; t.last = last; t.onEnterFrame = function(){ this["h"+counter++].removeMovieClip() if(counter==last) { delete this.onEnterFrame } } } /* * getter-setter for state * @param state could be single or icons */ private function setState(state:String):Void{ this.state = state } public function getState():String{ return state } }