package
{
import flash.display.MovieClip;
import bontos.BatchLoader;
import bontos.BatchLoaderEvent;
import flash.utils.Dictionary;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.display.BitmapData;
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
import flash.text.StyleSheet;
import bontos.firebugTracer.Fbug;
import bontos.ScrollerText;
import flash.utils.setTimeout;
public class Timeline extends MovieClip
{
private var batchM: BatchLoader = new BatchLoader(this);
private var batchB: BatchLoader;
private var itemsInfo: Dictionary = new Dictionary();
private var arrItems: Array = [];
private var arrDots: Array = [];
private var tmLine: TweenMax;
private var currLineIndex: int = 0;
private var currIndex: int = -1;
private var isTweenLine: Boolean = false;
public var detailInfo: DetailInfo;
public function Timeline()
{
line.y = 138;
tmLine = new TweenMax(line, .2, {width:0, paused: true, ease:Linear.easeNone, onComplete: onCompleteLine});
}
public function setData(xmlL: XML)
{
loadImages(xmlL);
detailInfo.alpha = 0;
detailInfo.y = 297;
detailInfo.x = 40;
}
public function showNext() : void
{
onDotOver(arrDots.length - 1 == currIndex ? 0 : currIndex + 1);
}
public function showPrev() : void
{
onDotOver(currIndex == 0 ? arrDots.length - 1 : currIndex - 1);
}
private function loadImages(xmlL: XML): void
{
//trace('start loading ...', xmlL.images.length());
var arrPositionsItems: Array = setPositionItems(xmlL);
batchB = new BatchLoader(detailInfo);
for(var i: int = 0; i < xmlL.images.length(); i++){
if(xmlL.images[i].@imgUrlm.toString().length > 5){
itemsInfo['imgM_' + xmlL.images[i].@imgUrlm] = {
year: xmlL.images[i].@year,
xPosImg: arrPositionsItems[i].xPosImg,//xmlL.images[i].@xPosImg,
xPosDot: arrPositionsItems[i].xPosDot,//xmlL.images[i].@xPosDot,
posY: arrPositionsItems[i].posY,//xmlL.images[i].@posY,
txt: br2n(xmlL.images[i].txt),
imgSrc: xmlL.images[i].@imgUrl}
//Fbug.info(i + ' _ ' + xmlL.images[i].@imgUrlm);
batchM.add(xmlL.images[i].@imgUrlm, 'imgM_' + xmlL.images[i].@imgUrlm);
}
}
detailInfo.addEventListener(BatchLoaderEvent.COMPLETE_LOAD, onLoadImgB);
addEventListener(BatchLoaderEvent.COMPLETE_LOAD, onBatchLoaded);
addEventListener(BatchLoaderEvent.COMPLETE_LOAD_ALL, onBatchLoadedAll);
batchM.start();
}
private function onBatchLoaded(ev: BatchLoaderEvent): void
{
//trace('loaded src by ', ev.alias);
//Fbug.info(arrItems.length + ' img loaded by alias ' + ev.alias);
if(arrItems.length == 1){
for(var key: Object in itemsInfo){
batchB.add(itemsInfo[key].imgSrc, 'imgB_' + itemsInfo[key].imgSrc);
};
batchB.start();
}
createItems(ev.alias);
}
private function onBatchLoadedAll(ev: BatchLoaderEvent): void
{
//trace('all resources loaded ', ev.alias);
//Fbug.info('all resources loaded ');
}
private function createItems(alias: String): void
{
line.x = line.x == 0 ? itemsInfo[alias].xPosDot : line.x;
var item: Item = new Item();
itemsInfo[alias].img = batchM.get(alias) as Bitmap;
item.alias = alias;
item.setData(itemsInfo[alias], onDotOver, onDotOut);
addChild(item);
arrItems.push(item);
item.index = arrItems.length - 1;
createDot(alias);
showItem();
}
private function createDot(alias: String): void
{
var dot: Dot = new Dot();
dot.x = itemsInfo[alias].xPosDot;
dot.y = line.y + 1;
dot.hideDetail = onDotOut;
dot.showDetail = onDotOver;
arrDots.push(dot);
dot.index = arrDots.length - 1;
addChild(dot);
}
private function onCompleteLine(): void
{
isTweenLine = false;
showDot(currLineIndex - 1);
showItemPreview(currLineIndex - 1);
if(arrItems.length > currLineIndex){
showItem();
}
}
private function showItem(): void
{
if(isTweenLine) return;
//Fbug.warn(' show Item' + currLineIndex);
if(currLineIndex != 0){
setLine()
}else{
showDot(currLineIndex);
showItemPreview(currLineIndex);
}
currLineIndex++;
}
private function setLine(): void
{
var xPosL: int = arrDots[currLineIndex].x;
tmLine.setDestination('width', xPosL - line.x);
tmLine.restart();
isTweenLine = true;
}
private function showDot(iL: int): void
{
arrDots[iL].show();
}
private function showItemPreview(iL: int): void
{
//Fbug.debug('showItemPreview ' + iL);
arrItems[iL].show();
}
private function onDotOver(indexL: int): void
{
if(indexL == currIndex) return;
if(currIndex > -1)
arrDots[currIndex].out();
hideDetailInfo();
arrDots[indexL].over();
showDetailInfo(indexL);
currIndex = indexL;
}
private function onDotOut(indexL: int): void
{
currIndex = indexL;
}
private var currDetailImgAlias: String = '';
private var myScroller: ScrollerText;
private function showDetailInfo(indexL: int): void
{
detailInfo.textMc.txt.styleSheet = getTAStyles();
detailInfo.textMc.txt.autoSize = "left";
(detailInfo.parent as DocClass).prevBtnClick.visible = (detailInfo.parent as DocClass).nextBtnClick.visible = true;
var obj: Object = itemsInfo[arrItems[indexL].alias];
currDetailImgAlias = 'imgB_' + obj.imgSrc;
detailInfo.yearTxt.text = obj.year;
//detailInfo.txt.text = obj.txt;
detailInfo.textMc.txt.htmlText = obj.txt;//"This text is in Bold
This text is in Italics";//
detailInfo.textMc.txt.embedFonts = true;
if(myScroller != null) {myScroller.removeSelf(); myScroller = null}
setTimeout(function ew43():void{
var maxHText: int = 170;
trace(detailInfo.textMc.txt.height, detailInfo.textMc.height);
if(detailInfo.textMc.txt.height > maxHText){
if(myScroller != null) {myScroller.removeSelf(); myScroller = null}
myScroller = new ScrollerText(detailInfo.textMc, detailInfo.textMc.width, maxHText, new scrollerFace(),"vertical");
}
}, 1);
//Fbug.debug('showDetailInfo ' + batchB.get(currDetailImgAlias) + ' _ __' + currDetailImgAlias);
//trace('__ on show Detail. ', currDetailImgAlias, batchB.get(currDetailImgAlias), obj.imgSrc);
if(batchB.get(currDetailImgAlias) != null)
showDetail();
else{
//batchB.add(obj.imgSrc, currDetailImgAlias);
//batchB.start();
};
}
private function getTAStyles(): StyleSheet
{
var my_styles: StyleSheet = new StyleSheet();
my_styles.setStyle("h1", {fontSize: "22px"});
my_styles.setStyle("h2", {fontSize: "16px"});
my_styles.setStyle("h3", {fontSize: "14px"});
my_styles.setStyle("h4", {fontSize: "12px"});
my_styles.setStyle("h5", {fontSize: "10px"});
my_styles.setStyle("h6", {fontSize: "10px"});
my_styles.setStyle("strong", {fontWeight: "bold"});
my_styles.setStyle("em", {fontStyle: "italic"});
my_styles.setStyle("a", {textDecoration: "underline"});
return my_styles;
}
private function hideDetailInfo(): void
{
TweenLite.to(detailInfo, 0.1, {alpha: 0});
}
private function showDetail(): void
{
//Fbug.debug('showDetail ' + batchB.get(currDetailImgAlias) + ' _ ' + currDetailImgAlias);
detailInfo.imgB.x = detailInfo.imgBUp.x;
detailInfo.imgB.y = detailInfo.imgBUp.y = 4;
trace('__ on show Detail. ', detailInfo.imgB.x, detailInfo.imgBUp.x, batchB.get(currDetailImgAlias));
detailInfo.imgBUp.x = Math.max((308 - batchB.get(currDetailImgAlias).width) / 2, 4);
//detailInfo.imgBUp.y = (228 - batchB.get(currDetailImgAlias).height) / 2 + 16;
//detailInfo.imgBUp.x = (detailInfo.width - batchB.get(currDetailImgAlias).width) / 2;
//detailInfo.imgBUp.y = (228 - batchB.get(currDetailImgAlias).height) / 2 + 16;
if(detailInfo.imgB.numChildren > 0)
detailInfo.imgB.removeChildAt(0);
if(detailInfo.imgBUp.numChildren > 0)
detailInfo.imgB.addChild(detailInfo.imgBUp.getChildAt(0));
detailInfo.imgBUp.addChild(batchB.get(currDetailImgAlias) as Bitmap);
detailInfo.bgImg.x = detailInfo.imgBUp.x - 4;
detailInfo.bgImg.y = detailInfo.imgBUp.y - 4;
detailInfo.bgImg.width = detailInfo.imgBUp.width + 8;
detailInfo.bgImg.height = detailInfo.imgBUp.height + 8;
detailInfo.bgImg.alpha = 0;
detailInfo.imgBUp.alpha = 0;
detailInfo.imgB.alpha = 1;
TweenMax.to(detailInfo.imgB, .4, {alpha:0});
TweenMax.to(detailInfo.imgBUp, .5, {alpha:1});
TweenMax.to(detailInfo.bgImg, .5, {alpha:1});
TweenLite.to(detailInfo, 0.3, {alpha: 1});
}
private function onLoadImgB(ev: BatchLoaderEvent): void
{
trace(ev.alias, currDetailImgAlias);
//Fbug.warn('onLoadImgB ' + currDetailImgAlias + ' _ ' + ev.alias);
if(currDetailImgAlias == ev.alias) showDetail();
}
private function setPositionItems(xmlL: XML): Array
{
var years: Array = [];
var i: int;
var period: int = 0;
var wItem = 150;
//var widthNeed: int = 0;
for(i = 0; i < xmlL.images.length(); i++){
years.push(xmlL.images[i].@year.toString());
}
var firstYear: int = Number(years[0]);
for(i = 0; i < years.length; i++){
years[i] = Number(years[i]) - firstYear;
}
period = years[years.length - 1] - years[0];
//widthNeed = years.length / 2 * 200 * 1.3;
var xI: int = 0;
var xD: int = 0;
var minPad: int = 45;
var newYear: Array = [];
var lengthOneYear: Number = 2;
if(years.length < 12){
//trace(650, years.length * (30 + 90) / 2, (650 - 480) / (years[years.length - 1] - years[0]));
lengthOneYear += (650 - years.length * 210 / 2) / years[years.length - 1];
trace(lengthOneYear, years[0]);
}
var lastYear: int = years[0];
for(i = 0; i < years.length; i++){
if(i == 0) {
xI = 5;
xD = 70;
}else{
xD = newYear[i - 1].xPosDot + minPad + (years[i] - years[i - 1]) * lengthOneYear;
xD = Math.max(newYear[i - 1].xPosDot + minPad, xD);
//xI = (years[i] - lastYear) > 10 ? 60 : 30;
xI = xD - 60;
if(newYear.length > 1 && xI < (newYear[i - 2].xPosImg + wItem)){
xD += (newYear[i - 2].xPosImg + wItem) - xI;
xI = (newYear[i - 2].xPosImg + wItem);
}
lastYear = years[i - 1];
}
trace('xI == ', xI, ', xD == ', xD, '. ');
newYear.push({
xPosImg: xI,
xPosDot: xD,
posY: i % 2});
}
return newYear;
}
function fixLineBreakTags(p_string: String): String
{
while (p_string.indexOf("") > -1) {
p_string = p_string.replace("", "");
}
while (p_string.indexOf("") > -1) {
p_string = p_string.replace("", "");
}
while (p_string.indexOf("\r\n") > -1) {
p_string = p_string.replace("\r\n", "\r");
}
while (p_string.indexOf("
") > -1) {
p_string = p_string.replace("
", "
");
}
while (p_string.indexOf("
") > -1) {
p_string = p_string.replace("
", "
");
}
while (p_string.indexOf(" ") > -1) {
p_string = p_string.replace(" ", "");
}
while (p_string.indexOf("