/*******************************************************************************
* @author Maria A. Zamora
* @company Digitec Interactive Inc.
* @version 0.1
* @date 12/14/2010
*
* ConceptsCEE class for conceptsFrame3 movie of the CEE application CS5 version
* of com.digitec.cee.ConceptsCEE
*
******************************************************************************/
package com.digitec.cee {
import gs.*;
import gs.easing.*;
import flash.display.MovieClip;
import flash.display.Sprite
import flash.events.*;
// import flash.events.TextEvent;
import flash.display.SimpleButton;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import fl.transitions.TweenEvent;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.*;
import flash.events.HTTPStatusEvent;
import flash.events.IOErrorEvent;
public class ConceptsCEE extends BaseCEE {
private var _xmlPath: String;
private var activeCat: Number;
// ARRAY OF CATEGORY OBJECTS
private var catList: Array;
private var numCategories: int;
private var maxCategories: int = 5;
// ARRAY OF CONCEPTS OBJECTS
// private var conceptsListArray:Array = new Array();
private var conceptsXML: XML;
private var currentConcept: int; // Current selected concept
private var startAnim_y: Number = 158; // for accordion animation
private var animSpeed: Number = 0.3; // .7 sec animation //SET
// ACCORDION ANIMATION SPEED
private var conceptsArray: Array = new Array();
private var $nc: NetConnection;
private var $ns: NetStream;
private var $streampath: String;
private var $streamurl: String = MainConstants.CEE_SERVER;
private var myFont: Font = new Font5();
private var versionField: TextField;
/***********************************************************************
* CONSTRUCTOR
**********************************************************************/
public function ConceptsCEE() {
super(MainConstants.XMLCONCEPTS);
setupPageButtons();
}
/***********************************************************************
* FUNCTION: SETUP FRAME TEXT_FIELDS FROM XML
**********************************************************************/
override public function setFramesText(_xml: XML): void {
// FIRST SET THE TEXT FIELDS
this.title_tf.text = _xml.xtitle;
this.titleInfo_tf.text = _xml.xtitleInfo;
var myFormat: TextFormat = new TextFormat();
myFormat.font = myFont.fontName;
myFormat.size = 12;
myFormat.color = 0x8DC269;
versionField = new TextField();
versionField.defaultTextFormat = myFormat;
versionField.embedFonts = true;
versionField.height = 17;
versionField.width = 50;
versionField.background = false;
versionField.border = false;
versionField.multiline = true;
versionField.wordWrap = true;
versionField.x = 415;
versionField.y = 581;
versionField.htmlText = "<b>" + _xml.xversion2 + "</b>";
loadingmenu.visible = true;
addChild(versionField);
this.register_tf.text = _xml.xregister;
// GET THE CATEGORIES FROM category NODES IN THE XML
// SET CATEGORY COUNT TO A MAX OF 5
numCategories = _xml.elements("category").length();
if (numCategories > maxCategories) {
numCategories = maxCategories;
}
// CREATE AN ARRAY OF CATEGORY OBJECTS
catList = new Array();
for (var i: int = 0; i < numCategories; i++) {
var thename: String = _xml.category[i].categoryName.toString();
var conceptcount: int = int(_xml.category[i].conceptCount);
var base_y: Number = this["cat" + i + "_mc"].y;
var theCategory: Category = new Category(i, thename, base_y, conceptcount);
catList[i] = theCategory;
this["cat" + i + "_mc"].buttonMode = false;
this["cat" + i + "_mc"].useHandCursor = false;
// SET TEXT FIELD IN CATEGORY CONCEPT MOVIES BUTTONS
this["cat" + i + "_mc"].catName_txt.text = thename; // this.conceptList_mc
this["cat" + i + "_mc"].conceptCount_txt.text = catList[i].conceptCount + " Concepts";
// this["cat" + i + "_mc"].catmc.addEventListener(
// MouseEvent.CLICK, selectCategory );
}
// LOAD THE CONCEPT LIST
var GETLISTXML = Object(parent).getDpath();
loadConceptList(GETLISTXML + "_VE50DATA/" + MainConstants.XMLPATH + MainConstants.XMLCONCEPTS_LIST);
}
private function httpStatusHandlerLIST(event: HTTPStatusEvent): void {
if (event.status == 0) {
var GETLISTXML = Object(parent).getDpath();
loadConceptList(GETLISTXML + "_VE50DATA/" + MainConstants.XMLPATH + MainConstants.XMLCONCEPTS_LIST);
} else {
loadConceptList($streamurl + MainConstants.XMLCONCEPTS_LIST);
}
}
/***********************************************************************
* FUNCTION: TO LOAD XML FILE
**********************************************************************/
private function ioErrorHandler(event: IOErrorEvent): void {
// trace("ioErrorHandler: " + event);
}
private function loadConceptList(stream: String): void {
// trace("Stream list "+stream);
var loader: URLLoader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
loader.load(new URLRequest(stream));
loader.addEventListener(Event.COMPLETE, loadData);
function loadData(evt: Event) {
conceptsXML = new XML(loader.data);
createConceptsArrayByCategory();
}
}
/***********************************************************************
* FUNCTION: MANIPULATION & RETREIVAL OF CONCEPT DATA
**********************************************************************/
private function createConceptsArrayByCategory(): void {
var numconcepts: int = conceptsXML.elements("concept").length();
for (var i: uint = 0; i < numconcepts; i++) {
// CREATE CONCEPTITEM OBJECT & INSERT IT IN CORRESPONDING
// CATEGORY
var conItem: ConceptItem = new ConceptItem(conceptsXML.concept[i]);
var num: int = conItem.categoryID;
catList[num].insertConceptToArray(conItem);
conceptsArray.push(conItem);
}
populate();
}
/***********************************************************************
* FUNCTION: RETURN TO MAIN ALL CONCEPT ARRAY
**********************************************************************/
public function getConceptArray(): Array {
return conceptsArray;
}
/***********************************************************************
* FUNCTION: POPULATE
**********************************************************************/
private function populate() {
var css: StyleSheet = new StyleSheet();
var gUrl: URLRequest = new URLRequest("data/conceptList.css"); // new
var gLoader: URLLoader = new URLLoader();
gLoader.load(gUrl);
gLoader.addEventListener(Event.COMPLETE, gLoaded);
function gLoaded(event: Event): void {
css.parseCSS(gLoader.data);
}
for (var j: uint = 0; j < catList.length; j++) {
var myArr: Array = new Array();
myArr = catList[j].conceptArray;
this["cat" + j + "_mc"].col1_mc.col_txt.htmlText = "";
this["cat" + j + "_mc"].col2_mc.col_txt.htmlText = "";
hideConcepts(j);
this["cat" + j + "_mc"].conceptCount_txt.text = "" + myArr.length + " concepts";
for (var i = 0; i < myArr.length; i++) {
var theField;
if (i < Math.ceil(myArr.length / 2)) {
theField = this["cat" + j + "_mc"].col1_mc.col_txt;
} else {
theField = this["cat" + j + "_mc"].col2_mc.col_txt;
}
// TEXTEVENT CANNOT BE APPLIED TO A TEXT FIELD WITH
// STYLESHEET????
theField.htmlText += "<a href='event:" + myArr[i].conceptID + "'><u>" + myArr[i].conceptName + "</u></a>\n";
theField.addEventListener(TextEvent.LINK, showConceptView);
}
this["cat" + j + "_mc"].listHeight = Math.ceil(myArr.length / 2);
this["cat" + j + "_mc"].catmc.addEventListener(MouseEvent.CLICK, selectCategory);
this["cat" + j + "_mc"].buttonMode = true;
this["cat" + j + "_mc"].useHandCursor = true;
}
loadingmenu.visible = false;
}
/***********************************************************************
* FUNCTIONS: SHOW THE CURRENT SELECTED CONCEPT IN LESSON PAGE
**********************************************************************/
public function showConceptView(event: TextEvent): void {
var id: int = new int(event.text);
trace("---SHOW CONCEPT VIEW = " + id);
gotoConceptLessons(retrieveConceptItem(id));
}
/***********************************************************************
* FUNCTION: RETRIEVE CONCEPT ITEM
**********************************************************************/
private function retrieveConceptItem(_theid: int): ConceptItem {
var myobj: ConceptItem;
var myArr: Array = catList[activeCat].conceptArray;
for (var i = 0; i < myArr.length; i++) {
if (myArr[i].conceptID == _theid) {
myobj = myArr[i];
}
}
return myobj;
}
/***********************************************************************
* FUNCTIONS: GO TO CONCEPT VIEW
**********************************************************************/
public function gotoConceptView(id: Number) {
if (id) {
currentConcept = id;
}
var item: ConceptItem = catList[this.activeCat];
}
/***********************************************************************
* FUNCTIONS: SELECT A CATEGORY HANDLER
**********************************************************************/
public function selectCategory(evt: MouseEvent): void {
var clicked: MovieClip = MovieClip(evt.target.parent); // RETURN
var currentCat: Number = Number(clicked.name.charAt(3)); // cat0_mc----
var numRow: Number = this["cat" + currentCat + "_mc"].listHeight
// NO MORE THAN 9 ROWS HEIGHT
if (numRow > 9) {
numRow = 9;
}
if (numRow < 4) {
numRow = 4;
} // to set a better looking display
// SET ANIMATION PROPS
var heightList: Number = numRow * 26; // previous static
// listheight = 200
// trace("heightList"+heightList);
this.cat0_mc.props = {
ly: 158,
ry: (123.35 + heightList),
ind: 1
}; // this.cat0_mc.props = {ly:158, ry:323.35, ind:1};
this.cat1_mc.props = {
ly: 190,
ry: (155.35 + heightList),
ind: 2
}; // this.cat1_mc.props = {ly:190, ry:355.35, ind:2};
this.cat2_mc.props = {
ly: 222,
ry: (187.35 + heightList),
ind: 3
}; // this.cat2_mc.props = {ly:222, ry:387.35, ind:3};
this.cat3_mc.props = {
ly: 254,
ry: (219.35 + heightList),
ind: 4
}; // this.cat3_mc.props = {ly:254, ry:419.35, ind:4};
this.cat4_mc.props = {
ly: 286,
ry: (251.35 + heightList),
ind: 5
}; // this.cat4_mc.props = {ly:286, ry:451.35, ind:5};
// START ACCORDION ANIMATION
for (var i: int = 0; i < 5; i++) {
var mc: MovieClip = MovieClip(this["cat" + i + "_mc"]);
if (mc.props.ind == clicked.props.ind) {
mc.arrow_mc.rotation = 90;
var tween: TweenLite = TweenLite.to(mc, animSpeed, {
alpha: 1,
y: mc.props.ly,
ease: Linear.easeOut,
delay: 0,
onComplete: onFinishTween,
onCompleteParams: [1, mc]
});
function onFinishTween(arg1: Number, arg2: MovieClip): void {
showConcepts(currentCat);
}
activeCat = i;
} else if (mc.props.ind < clicked.props.ind) {
hideConcepts(i);
mc.arrow_mc.rotation = 0;
TweenLite.to(mc, animSpeed, {
y: mc.props.ly,
ease: Linear.easeOut
}); // .7 sec animation
} else {
hideConcepts(i);
mc.arrow_mc.rotation = 0;
TweenLite.to(mc, animSpeed, {
y: mc.props.ry,
ease: Linear.easeOut
});
}
}
}
/***********************************************************************
* FUNCTIONS: HIDE & SHOW THE CURRENT CATEGORY CONCEPTS
**********************************************************************/
public function hideConcepts(catnum: Number) {
this["cat" + catnum + "_mc"].col1_mc.visible = false; // this.conceptList_mc
this["cat" + catnum + "_mc"].col2_mc.visible = false;
}
public function showConcepts(catNum: Number) {
this["cat" + catNum + "_mc"].col1_mc.visible = true;
this["cat" + catNum + "_mc"].col2_mc.visible = true;
}
public function showActive() {
showConcepts(this.activeCat);
}
/***********************************************************************
* FUNCTION: SET UP ALL BUTTONS AND TEXTFIELDS
**********************************************************************/
private function setupPageButtons(): void {
this.close_button.buttonMode = true;
this.close_button.mouseChildren = false;
this.close_button.useHandCursor = true;
this.close_button.addEventListener(MouseEvent.MOUSE_OVER, onCloseOver);
this.close_button.addEventListener(MouseEvent.MOUSE_OUT, onCloseOut);
this.close_button.addEventListener(MouseEvent.CLICK, onCloseClick);
this.about2_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoAboutFrm);
this.nav_back_button.addEventListener(MouseEvent.MOUSE_OVER, onNavBackOver);
this.nav_back_button.addEventListener(MouseEvent.MOUSE_OUT, onNavBackOut);
this.nav_back_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoLastFrm);
this.nav_home_button.addEventListener(MouseEvent.MOUSE_OVER, onNavHomeOver);
this.nav_home_button.addEventListener(MouseEvent.MOUSE_OUT, onNavHomeOut);
this.nav_home_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoHomeFrm);
this.nav_concepts_button.addEventListener(MouseEvent.MOUSE_OVER, onNavConceptsOver);
this.nav_concepts_button.addEventListener(MouseEvent.MOUSE_OUT, onNavConceptsOut);
this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_OVER, onNavLessonsOver);
this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_OUT, onNavLessonsOut);
this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoSearchFrm);
}
/***********************************************************************
* FUNCTIONS: BUTTONS ROLL OVER & OUT
**********************************************************************/
private function onCloseOver(evt: MouseEvent): void {
close_button.gotoAndStop(2);
}
private function onCloseOut(evt: MouseEvent): void {
close_button.gotoAndStop(1);
}
private function onNavBackOver(evt: MouseEvent): void {
back_icon_roll.gotoAndStop(2);
}
private function onNavBackOut(evt: MouseEvent): void {
back_icon_roll.gotoAndStop(1);
}
private function onNavHomeOver(evt: MouseEvent): void {
house_mc.gotoAndStop(2);
}
private function onNavHomeOut(evt: MouseEvent): void {
house_mc.gotoAndStop(1);
}
private function onNavConceptsOver(evt: MouseEvent): void {
nav_concepts_roll.gotoAndStop(2);
}
private function onNavConceptsOut(evt: MouseEvent): void {
nav_concepts_roll.gotoAndStop(1);
}
private function onNavLessonsOver(evt: MouseEvent): void {
nav_lessons_roll.gotoAndStop(2);
}
private function onNavLessonsOut(evt: MouseEvent): void {
nav_lessons_roll.gotoAndStop(1);
}
} // Main class
} // end package