Newer
Older
CEE_VE50 / com / digitec / cee / ConceptList.as
@cwolsen cwolsen on 19 Jun 2019 4 KB Initial Import
// FUNCTIONS THAT CONTROL THE CONCEPT LIST ACCORDION
package com.digitec.cee
{
    import flash.display.Sprite
	import flash.events.*;
	//import fl.data.DataProvider;
	//import fl.controls.List
	//import fl.controls.Label
	//import fl.controls.Button
    
    public class ConceptList extends Sprite
    {		        
     	//   private var clearButton:Button;
    	//   private var availableItems:List;
    	//   private var selectedItemList:List;
    	//   private var selectedItemsList:List;
	 
		private var catList:Array = new Array();
		// define the categories		
		private var activeCat:Number;

        public function ConceptList()
		{
         	//createComponents();
        	//setupComponents();
			catList = ["Fundamental Economics","Macroeconomics","Microeconomics","International Economics","Personal Finance Economics"];				
        }		
		
	//initConceptList = function() {
		//conceptList_mc.selectCategory = function(cat:Number):Void {
		public function selectCategory( cat:Number ):void
		{
			//trace("! Select category : " + this.catList[cat]);
			this.activeCat = cat;			
			
			//appRoot.cList_current = cat;
			
			// tween all MCs to their proper position
			for (var i=0; i<this.catList.length; i++)
			{
				var theMC = this["cat" + i + "_mc"];
				var offset = 10 + (20*this["cat" + cat + "_mc"].listHeight);
				theMC.stopTween();
				theMC.arrow_mc.stopTween();
			if (i == cat)
			{
				var theFunc = function() 
				{
					this.showConcepts();
				}
				callback = {scope: theMC, func: theFunc};
				theMC.arrow_mc.tween("rotation",90,.25);
				theMC.tween("y",theMC.baseY,.5,"easeOutExpo",0,callback);
			} else if (i > cat)	{
				theMC.arrow_mc.tween("rotation",0,.25);
				theMC.tween("y",theMC.baseY+offset,0.5,"easeOutExpo");
				theMC.hideConcepts();
			} else {
				theMC.arrow_mc.tween("rotation",0,.25);
				theMC.tween("y",theMC.baseY,0.5,"easeOutExpo");
				theMC.hideConcepts();
			}
		}
	}
	
	public function hideConcepts()
	{
		//trace("hide");
		this.col1_mc._visible = false;
		this.col2_mc._visible = false;
	}
	
	public function showConcepts()
	{
		//trace("show");
		this.col1_mc._visible = true;
		this.col2_mc._visible = true;
	}
	
	public function showActive()
	{
		this["cat" + this.activeCat + "_mc"].showConcepts();
	}
	
	
	// Begin setting up a category
	// tweak the textfields by applying some styles
	for (var j=0; j<conceptList_mc.catList.length; j++) 
	{
		conceptList_mc["cat" + j + "_mc"].col1_mc.col_txt.styleSheet = appRoot.cssLib.conceptList_css;
		conceptList_mc["cat" + j + "_mc"].col2_mc.col_txt.styleSheet = appRoot.cssLib.conceptList_css;
	}
	
	conceptList_mc.my_styleSheet.load("conceptList.css");
	
	// populate the categories
	for (var j=0; j<conceptList_mc.catList.length; j++) {
		var theCategory = conceptList_mc["cat" + j + "_mc"];
		theCategory.hideConcepts = conceptList_mc.hideConcepts;
		theCategory.showConcepts = conceptList_mc.showConcepts;
		theCategory.myCat = j;
		theCategory.baseY = theCategory._y;
		theCategory.catName_txt.text = conceptList_mc.catList[j];
		var cList:Array = new Array();
		cList = appRoot.getConceptsByCategory(j); // get concept list for a category
		theCategory.col1_mc.col_txt.htmlText = "";
		theCategory.col2_mc.col_txt.htmlText = "";
		theCategory.hideConcepts();
		theCategory.conceptCount_txt.text = cList.length + " concepts";
		for (var i=0; i<cList.length; i++) {
			var theField;
			if (i<Math.ceil(cList.length/2)) {
				theField = theCategory.col1_mc.col_txt;
			} else {
				theField = theCategory.col2_mc.col_txt;
			}
			theField.htmlText += "<p><a href=\"asfunction:appRoot.showConcept," + cList[i].id + "\">" + cList[i].name + "</a></p>\n";
			}
		theCategory.listHeight = Math.ceil(cList.length/2);
		// assign button actions
		
		theCategory.cat_btn.onRelease = function() {
			this._parent._parent.selectCategory(this._parent.myCat);			
		}
	}
	
	// set the back button
	/*
	back_mc.back_txt.text = "BACK TO MAIN";
	back_mc.back_btn.onRelease = function() {
		appRoot.gotoMain();
	}
	*/	
	
	if (appRoot.cList_current != undefined)
	{
		conceptList_mc.selectCategory(appRoot.cList_current);
	}
	
	
	
} //end of class

	} //end of package