daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import mx.transitions.Tween;
  2. import flash.external.ExternalInterface;
  3. pageRefresh = true;
  4. alert = function(value) {
  5.     // print value to Firebug for debugging
  6.     ExternalInterface.call("FB_Trace", value);
  7. }
  8. ExternalInterface.addCallback("updateSegment", this, updateSegment);
  9. function updateSegment(num:Number):Void {
  10.     _root.segment = num-1;
  11.     resizeTimeline(divWidth, maxCols, num);
  12. }
  13. function setActivity(id):Void {
  14.     ExternalInterface.call("set_activity", id);
  15.     ExternalInterface.call("reload_responses", true);
  16. }
  17. function approveActivity(id):Void {
  18.     ExternalInterface.call("moderator.approve_activity", id);
  19. }
  20. ExternalInterface.addCallback("resizeTimeline", this, resizeTimeline);
  21. function resizeTimeline(newWidth, maxColumns):Void {
  22.     if(!error) {
  23.         maxCols = maxColumns;
  24.         _root.divWidth = newWidth;
  25.         _root.stageWidth = newWidth;
  26.         timelineWidth = newWidth;
  27.         Timeline.init();
  28.     }
  29. }
  30.  
  31. var duration:Number;
  32. var error = 0;
  33. if(!segment) var segment:Number;
  34. var Project:Object = new Object();
  35.  
  36. // LOAD StyleSheet
  37. _global.globalStyles = new TextField.StyleSheet();
  38. _global.globalStyles.load("/stylesheets/timeline_flash.css");
  39. _global.globalStyles.onLoad = function(success) {
  40.     if(success) {
  41.         loadXML();
  42.     } else {
  43.         error = 1;
  44.         status_txt = "Error loading stylesheet";
  45.     }
  46. }
  47. // LOAD Project Data
  48. function loadXML() {
  49.     var XMLData:XML = new XML();
  50.     XMLData.load(timeline_data);
  51.     XMLData.ignoreWhite = true;
  52.     XMLData.onLoad = function(success:Boolean):Void
  53.     {
  54.         if(success) {
  55.             l_mc._visible = false;
  56.             parseThisMama(this);
  57.             ExternalInterface.call("resizeTimeline", null);
  58.             //Timeline.init(segment-1);
  59.         } else {
  60.             error = 1;
  61.             l_mc._visible = false;
  62.             status_txt.text = "Error loading data";
  63.             alert("Error Loading XML");
  64.         }
  65.     }
  66. }
  67.  
  68. function parseThisMama(xmlObj:XML):Void
  69. {
  70.     var rootNode = xmlObj.firstChild;
  71.     aNum = 0;
  72.     // get project site, name, id
  73.     Project.length = rootNode.attributes['length'];
  74.     Project.name = rootNode.attributes['name'];
  75.     Project.id = rootNode.attributes['id'];
  76.     Project.site = rootNode.attributes['site'];
  77.     for(var aNode:XMLNode = rootNode.firstChild; aNode != null; aNode = aNode.nextSibling)
  78.     {
  79.         Project["segment"+aNum] = new Object(); bNum = 0;
  80.         Project["segment"+aNum].length = aNode.attributes['length']*1;
  81.         Project["segment"+aNum].day = aNode.attributes['day']*1;
  82.         Project["segment"+aNum].name = aNode.attributes['name'];
  83.         Project["segment"+aNum].participants = aNode.attributes['participants']*1;
  84.         Project["segment"+aNum].id = aNode.attributes['id']*1;
  85.         for(var bNode:XMLNode = aNode.firstChild; bNode != null; bNode = bNode.nextSibling)
  86.         {
  87.             Project["segment"+aNum]['activity'+bNum] = [];
  88.             Project["segment"+aNum]['activity'+bNum].status = bNode.attributes['status'];
  89.             Project["segment"+aNum]['activity'+bNum].visibility = bNode.attributes['visibility'];
  90.             Project["segment"+aNum]['activity'+bNum].day = bNode.attributes['day']*1;
  91.             Project["segment"+aNum]['activity'+bNum].type = bNode.attributes['type'];
  92.             Project["segment"+aNum]['activity'+bNum].edit = bNode.attributes['edit'];
  93.             Project["segment"+aNum]['activity'+bNum].id = bNode.attributes['id']*1;
  94.             Project["segment"+aNum]['activity'+bNum].responses = bNode.attributes['responses']*1;
  95.             Project["segment"+aNum]['activity'+bNum].value = bNode.firstChild;
  96.             bNum ++;
  97.         }
  98.         Project["segment"+aNum].children = bNum;
  99.         aNum ++;
  100.     }
  101.     Project.segments = aNum;
  102. }
  103.  
  104. // TIMELINE
  105. var bgColor = 0xFFFFFF;
  106. var bgToday = 0xFFCC66;
  107. var borderColor = 0xD6D6C5;
  108. var colWidth;
  109. var colHeight;
  110. var padding = 11;
  111. var timelineWidth = _root.stageWidth-padding;
  112. var colWidth;
  113. var maxCols = 4;
  114. var movieHeight;
  115. var Timeline:Object = new Object();
  116. Timeline.init = function(num:Number):Void
  117. {
  118.     createEmptyMovieClip("mc", 1);
  119.     Timeline.rowValues = [];
  120.     _root.duration = Project.length;   
  121.     attachMovie("key", "key", 1000);
  122.     attachMovie('status_bar','status_bar', 0);
  123.     if(Project.length <= maxCols) {
  124.         status_bar.arrow_right._visible = false;
  125.         status_bar.arrow_left._visible = false;
  126.     }
  127.     for(i=0; i<40; i++){
  128.         Timeline.rowValues.push(0);
  129.     }
  130.     Timeline.populate();
  131. }
  132. Timeline.populate = function():Void
  133. {
  134.     //_root.segment = segment;
  135.     displayLength = Project.length < maxCols ? Project.length : maxCols;
  136.     colWidth = Math.floor(timelineWidth/displayLength);
  137.     timelineWidth = colWidth*Project.length;
  138.     segment = isNaN(segment) ? "all" : segment;
  139.     if(segment != "all") {
  140.         // Convert segment id into array index
  141.         for(j=0;j<Project.segments;j++) {
  142.             if((Project["segment"+j].id*1)-1 == segment) {
  143.                 segment = j;
  144.                 break;
  145.             }
  146.         }
  147.     }
  148.     // for all segments wrap inside another loop
  149.     for(i=1;i<=Project.length; i++) {
  150.         mc.attachMovie("keyNode", "keyNode"+i, i);
  151.         mc["keyNode"+i].day = i;
  152.         mc["keyNode"+i].segment = segment;
  153.         mc["keyNode"+i].w = colWidth;
  154.         mc["keyNode"+i].border_mc._height = movieHeight-40;
  155.         mc["keyNode"+i]._x = padding+(i-1)*(colWidth);
  156.     }
  157. }
  158.  
  159. setMovieHeight = function() {
  160.     if(pageRefresh) {
  161.         colActivityTotals = 0;
  162.         for(i=0; i<=Project.length; i++) {
  163.             if(mc["keyNode"+i].getRows() > colActivityTotals) {
  164.                 colActivityTotals = mc["keyNode"+i].getRows();
  165.             }
  166.         }
  167.         colActivityTotals = colActivityTotals < 2 ? 2 : colActivityTotals+1;
  168.         _root.movieHeight = ((colActivityTotals)*48)+60;
  169.         ExternalInterface.call("setFlashObjectHeight", movieHeight);
  170.         pageRefresh = false;
  171.     }
  172.     for(i=0; i<=Project.length; i++) {
  173.         mc["keyNode"+i].border_mc._height = (movieHeight-40);
  174.         mc["keyNode"+i].day_txt._y = movieHeight-83;
  175.         mc["keyNode"+i].today_txt._y = movieHeight-55
  176.         key.day._y = movieHeight-70;
  177.     }
  178.    
  179.     status_bar._y = movieHeight;
  180.     key.key_bg._height = movieHeight-40;
  181. }
  182. // NEED MORE COLORS!
  183. colors = ["0xfa8f0f", "0xade78f", "0x8fdae7", "0x336699", "0xFF3366", "0xCC33CC"];
  184. generateColor = function(num):String {
  185.     return colors[num];
  186. }
  187. var setTimeOut;
  188. showDropDown = function(x, y, hash) {
  189.     mc["keyNode"+curHighlight].select();
  190.     clearInterval(setTimeOut); 
  191.     if(x) {
  192.         mc.attachMovie('dropdown_mc', 'dropdown', 2000);
  193.         mc.dropdown._x = -2000;
  194.     }
  195.     mc.dropdown.id = hash.id;
  196.     mc.dropdown.responses = hash.responses;
  197.     mc.dropdown.visibility = hash.visibility;
  198.     mc.dropdown.value = hash.value;
  199.     mc.dropdown.status = hash.status;
  200.     mc.dropdown.day = hash.day;
  201.     mc.dropdown.edit = hash.edit;
  202.     mc.dropdown.segment = hash.segment;
  203.     if(x) mc.dropdown._x = x;
  204.     if(y) mc.dropdown._y = y;
  205.     if(x) {
  206.         if((x+mc._x)> (_root.stageWidth-220)) {
  207.             mc.dropdown.gotoAndStop(2);
  208.         }
  209.     }
  210. }
  211. hideDropDown = function() {
  212.     mc["keyNode"+curHighlight].deselect();
  213.     setTimeOut = setInterval(function() {
  214.         mc.dropdown.fade();
  215.         clearInterval(setTimeOut);
  216.       }, 600);
  217. }
  218. scrollTimeline = function(dir) {
  219.     if(!inMotion) {
  220.         inMotion = 1;
  221.         total = Project.length;
  222.         vis = maxCols;
  223.         scrollLength = 4;
  224.         // scroll by scrollLength * colWidth at a time unless there are less then scrollLength to go
  225.         if(dir == 1) {
  226.             neg = -(mc._x*1)/colWidth;
  227.             colsToGo = total-(vis+neg);
  228.             num = colsToGo < scrollLength ? ((colsToGo*colWidth)*dir) : ((scrollLength*colWidth)*dir);
  229.         } else {
  230.             neg = -(mc._x*1)/colWidth;
  231.             colsToGo = neg;
  232.             num = colsToGo < scrollLength ? ((colsToGo*colWidth)*dir) : ((scrollLength*colWidth)*dir);     
  233.         }
  234.         var myTween:Tween = new Tween(mc, "_x", mx.transitions.easing.Regular.easeOut,mc._x, mc._x-num, 8, false);
  235.         myTween.start();
  236.         myTween.onMotionFinished = function() {
  237.             inMotion = 0;
  238.             if(dir == 1 and colsToGo <= 4) {
  239.                 status_bar.arrow_right.disable();
  240.             } else {
  241.                 status_bar.arrow_right.enable();       
  242.             }
  243.             if(mc._x == 0) {
  244.                 status_bar.arrow_left.disable();
  245.             } else {
  246.                 status_bar.arrow_left.enable();    
  247.             }
  248.         }      
  249.     }
  250. }
RAW Paste Data
Top