Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mx.transitions.Tween;
- import flash.external.ExternalInterface;
- pageRefresh = true;
- alert = function(value) {
- // print value to Firebug for debugging
- ExternalInterface.call("FB_Trace", value);
- }
- ExternalInterface.addCallback("updateSegment", this, updateSegment);
- function updateSegment(num:Number):Void {
- _root.segment = num-1;
- resizeTimeline(divWidth, maxCols, num);
- }
- function setActivity(id):Void {
- ExternalInterface.call("set_activity", id);
- ExternalInterface.call("reload_responses", true);
- }
- function approveActivity(id):Void {
- ExternalInterface.call("moderator.approve_activity", id);
- }
- ExternalInterface.addCallback("resizeTimeline", this, resizeTimeline);
- function resizeTimeline(newWidth, maxColumns):Void {
- if(!error) {
- maxCols = maxColumns;
- _root.divWidth = newWidth;
- _root.stageWidth = newWidth;
- timelineWidth = newWidth;
- Timeline.init();
- }
- }
- var duration:Number;
- var error = 0;
- if(!segment) var segment:Number;
- var Project:Object = new Object();
- // LOAD StyleSheet
- _global.globalStyles = new TextField.StyleSheet();
- _global.globalStyles.load("/stylesheets/timeline_flash.css");
- _global.globalStyles.onLoad = function(success) {
- if(success) {
- loadXML();
- } else {
- error = 1;
- status_txt = "Error loading stylesheet";
- }
- }
- // LOAD Project Data
- function loadXML() {
- var XMLData:XML = new XML();
- XMLData.load(timeline_data);
- XMLData.ignoreWhite = true;
- XMLData.onLoad = function(success:Boolean):Void
- {
- if(success) {
- l_mc._visible = false;
- parseThisMama(this);
- ExternalInterface.call("resizeTimeline", null);
- //Timeline.init(segment-1);
- } else {
- error = 1;
- l_mc._visible = false;
- status_txt.text = "Error loading data";
- alert("Error Loading XML");
- }
- }
- }
- function parseThisMama(xmlObj:XML):Void
- {
- var rootNode = xmlObj.firstChild;
- aNum = 0;
- // get project site, name, id
- Project.length = rootNode.attributes['length'];
- Project.name = rootNode.attributes['name'];
- Project.id = rootNode.attributes['id'];
- Project.site = rootNode.attributes['site'];
- for(var aNode:XMLNode = rootNode.firstChild; aNode != null; aNode = aNode.nextSibling)
- {
- Project["segment"+aNum] = new Object(); bNum = 0;
- Project["segment"+aNum].length = aNode.attributes['length']*1;
- Project["segment"+aNum].day = aNode.attributes['day']*1;
- Project["segment"+aNum].name = aNode.attributes['name'];
- Project["segment"+aNum].participants = aNode.attributes['participants']*1;
- Project["segment"+aNum].id = aNode.attributes['id']*1;
- for(var bNode:XMLNode = aNode.firstChild; bNode != null; bNode = bNode.nextSibling)
- {
- Project["segment"+aNum]['activity'+bNum] = [];
- Project["segment"+aNum]['activity'+bNum].status = bNode.attributes['status'];
- Project["segment"+aNum]['activity'+bNum].visibility = bNode.attributes['visibility'];
- Project["segment"+aNum]['activity'+bNum].day = bNode.attributes['day']*1;
- Project["segment"+aNum]['activity'+bNum].type = bNode.attributes['type'];
- Project["segment"+aNum]['activity'+bNum].edit = bNode.attributes['edit'];
- Project["segment"+aNum]['activity'+bNum].id = bNode.attributes['id']*1;
- Project["segment"+aNum]['activity'+bNum].responses = bNode.attributes['responses']*1;
- Project["segment"+aNum]['activity'+bNum].value = bNode.firstChild;
- bNum ++;
- }
- Project["segment"+aNum].children = bNum;
- aNum ++;
- }
- Project.segments = aNum;
- }
- // TIMELINE
- var bgColor = 0xFFFFFF;
- var bgToday = 0xFFCC66;
- var borderColor = 0xD6D6C5;
- var colWidth;
- var colHeight;
- var padding = 11;
- var timelineWidth = _root.stageWidth-padding;
- var colWidth;
- var maxCols = 4;
- var movieHeight;
- var Timeline:Object = new Object();
- Timeline.init = function(num:Number):Void
- {
- createEmptyMovieClip("mc", 1);
- Timeline.rowValues = [];
- _root.duration = Project.length;
- attachMovie("key", "key", 1000);
- attachMovie('status_bar','status_bar', 0);
- if(Project.length <= maxCols) {
- status_bar.arrow_right._visible = false;
- status_bar.arrow_left._visible = false;
- }
- for(i=0; i<40; i++){
- Timeline.rowValues.push(0);
- }
- Timeline.populate();
- }
- Timeline.populate = function():Void
- {
- //_root.segment = segment;
- displayLength = Project.length < maxCols ? Project.length : maxCols;
- colWidth = Math.floor(timelineWidth/displayLength);
- timelineWidth = colWidth*Project.length;
- segment = isNaN(segment) ? "all" : segment;
- if(segment != "all") {
- // Convert segment id into array index
- for(j=0;j<Project.segments;j++) {
- if((Project["segment"+j].id*1)-1 == segment) {
- segment = j;
- break;
- }
- }
- }
- // for all segments wrap inside another loop
- for(i=1;i<=Project.length; i++) {
- mc.attachMovie("keyNode", "keyNode"+i, i);
- mc["keyNode"+i].day = i;
- mc["keyNode"+i].segment = segment;
- mc["keyNode"+i].w = colWidth;
- mc["keyNode"+i].border_mc._height = movieHeight-40;
- mc["keyNode"+i]._x = padding+(i-1)*(colWidth);
- }
- }
- setMovieHeight = function() {
- if(pageRefresh) {
- colActivityTotals = 0;
- for(i=0; i<=Project.length; i++) {
- if(mc["keyNode"+i].getRows() > colActivityTotals) {
- colActivityTotals = mc["keyNode"+i].getRows();
- }
- }
- colActivityTotals = colActivityTotals < 2 ? 2 : colActivityTotals+1;
- _root.movieHeight = ((colActivityTotals)*48)+60;
- ExternalInterface.call("setFlashObjectHeight", movieHeight);
- pageRefresh = false;
- }
- for(i=0; i<=Project.length; i++) {
- mc["keyNode"+i].border_mc._height = (movieHeight-40);
- mc["keyNode"+i].day_txt._y = movieHeight-83;
- mc["keyNode"+i].today_txt._y = movieHeight-55
- key.day._y = movieHeight-70;
- }
- status_bar._y = movieHeight;
- key.key_bg._height = movieHeight-40;
- }
- // NEED MORE COLORS!
- colors = ["0xfa8f0f", "0xade78f", "0x8fdae7", "0x336699", "0xFF3366", "0xCC33CC"];
- generateColor = function(num):String {
- return colors[num];
- }
- var setTimeOut;
- showDropDown = function(x, y, hash) {
- mc["keyNode"+curHighlight].select();
- clearInterval(setTimeOut);
- if(x) {
- mc.attachMovie('dropdown_mc', 'dropdown', 2000);
- mc.dropdown._x = -2000;
- }
- mc.dropdown.id = hash.id;
- mc.dropdown.responses = hash.responses;
- mc.dropdown.visibility = hash.visibility;
- mc.dropdown.value = hash.value;
- mc.dropdown.status = hash.status;
- mc.dropdown.day = hash.day;
- mc.dropdown.edit = hash.edit;
- mc.dropdown.segment = hash.segment;
- if(x) mc.dropdown._x = x;
- if(y) mc.dropdown._y = y;
- if(x) {
- if((x+mc._x)> (_root.stageWidth-220)) {
- mc.dropdown.gotoAndStop(2);
- }
- }
- }
- hideDropDown = function() {
- mc["keyNode"+curHighlight].deselect();
- setTimeOut = setInterval(function() {
- mc.dropdown.fade();
- clearInterval(setTimeOut);
- }, 600);
- }
- scrollTimeline = function(dir) {
- if(!inMotion) {
- inMotion = 1;
- total = Project.length;
- vis = maxCols;
- scrollLength = 4;
- // scroll by scrollLength * colWidth at a time unless there are less then scrollLength to go
- if(dir == 1) {
- neg = -(mc._x*1)/colWidth;
- colsToGo = total-(vis+neg);
- num = colsToGo < scrollLength ? ((colsToGo*colWidth)*dir) : ((scrollLength*colWidth)*dir);
- } else {
- neg = -(mc._x*1)/colWidth;
- colsToGo = neg;
- num = colsToGo < scrollLength ? ((colsToGo*colWidth)*dir) : ((scrollLength*colWidth)*dir);
- }
- var myTween:Tween = new Tween(mc, "_x", mx.transitions.easing.Regular.easeOut,mc._x, mc._x-num, 8, false);
- myTween.start();
- myTween.onMotionFinished = function() {
- inMotion = 0;
- if(dir == 1 and colsToGo <= 4) {
- status_bar.arrow_right.disable();
- } else {
- status_bar.arrow_right.enable();
- }
- if(mc._x == 0) {
- status_bar.arrow_left.disable();
- } else {
- status_bar.arrow_left.enable();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment