home *** CD-ROM | disk | FTP | other *** search
/ Twoje Kino Czerwiec 2005 / TwojeKINO.iso / cinema / shell.as < prev    next >
Text File  |  2005-02-24  |  11KB  |  459 lines

  1. 
  2. import com.macromedia.flashvideogallery.*;
  3.  
  4.  
  5.  
  6.  
  7.  
  8. var firstFrameExporter:MovieClip;
  9. var cover:MovieClip;
  10. var zIndex:Number = 1;
  11. var xmlFileToLoad:String = "content.xml";
  12.  
  13. // XML data is stored in the following. These correspond to the top level nodes.
  14. var labels:Object;
  15. var regions:Object;
  16. var sites:Array;
  17.  
  18. // Number of sites. Used throughout for looping.
  19. var siteCount:Number;
  20.  
  21.  
  22.  
  23. // Store the check boxes in an array for filtering.
  24. var regionCheckBoxArray:Array;
  25.  
  26. // Number of CheckBoxes for each filter.
  27. var regionCheckBoxCount:Number;
  28.  
  29. // Listeners for the CheckBoxes.
  30. var checkBoxListener:Object;
  31.  
  32.  
  33. // Detail view on the right.
  34. var detailView:MovieClip;
  35.  
  36. // Assets in the welcome area.
  37. var logo:MovieClip;
  38. var title:TextField;
  39.  
  40.  
  41.  
  42. // Stores all of the thumbs.
  43. var thumbArray:Array;
  44.  
  45. // Used in Thumb for swapDepths() when mousing over.
  46. var topThumb:MovieClip;
  47.  
  48. // Bubble RollOver text.
  49. var thumbRolloverText:MovieClip;
  50.  
  51. // Number of MovieClips to change when viewing/hiding detail.
  52. var mainMovieClipCount:Number;
  53.  
  54. function init():Void
  55. {
  56.     firstFrameExporter.unloadMovie();
  57.     
  58.     var contentXML:XML = new XML();
  59.     contentXML.ignoreWhite = true;
  60.     contentXML["container"] = this;    // "Trick" the compiler into adding a dynamic property to the XML object.
  61.                                     // Dot syntax will create a compiler error.
  62.     contentXML.onLoad = function(success:Boolean)
  63.     {
  64.         if (success)
  65.         {
  66.             this["container"].onXMLLoaded(this);
  67.         }
  68.     }
  69.     contentXML.load(xmlFileToLoad);
  70. }
  71.  
  72. function onXMLLoaded(contentXML:XML):Void
  73. {
  74.     // Parse through the XML.
  75.     var node:Object = contentXML.firstChild.firstChild;
  76.     while (node != null)
  77.     {
  78.         switch (node.nodeName)
  79.         {
  80.             case "naglowki":
  81.                 labels = xmlNodesToObject(new Object(), node);
  82.                 break;
  83.             case "premiery":
  84.                 regions = xmlNodesToObject(new Object(), node);
  85.                   break;
  86.             case "filmy":
  87.                 sites = xmlSiteNodesToArray(node);
  88.                 break;
  89.         }
  90.         
  91.            node = node.nextSibling;
  92.        }
  93.  
  94.     siteCount = sites.length;
  95.     
  96.     
  97.     
  98.     onXMLParsed();
  99. }
  100.  
  101. function xmlSiteNodesToArray(node:Object):Array
  102. {
  103.     var sites:Array = new Array();
  104.     var site:Object;
  105.     var siteNode:Object;
  106.     
  107.     var childNode:Object = node.firstChild;
  108.     while (childNode != null)
  109.     {
  110.         // Create a new site Object to store the data.
  111.         site = xmlAttributesToObject(new Object(), childNode);
  112.         
  113.         // Store the region and industry IDs in an array for filtering later.
  114.         // Regions and industries are attributes in the <site> node.
  115.         site.regions = site.data.split(",");
  116.         
  117.         siteNode = childNode.firstChild;
  118.         while (siteNode != null)
  119.         {
  120.             switch (siteNode.nodeName)
  121.             {
  122.                 case "developers":
  123.                     // Store the developers in an Array of Objects that contain the
  124.                     // developer URL and title.
  125.                     site.developers = xmlDeveloperNodesToArray(siteNode);
  126.                     break;
  127.                 default:
  128.                     site[siteNode.nodeName] = siteNode.firstChild.nodeValue;
  129.                     break;
  130.             }
  131.             siteNode = siteNode.nextSibling;
  132.         }
  133.  
  134.         sites.push(site);
  135.         
  136.         childNode = childNode.nextSibling;
  137.     }
  138.     return sites;
  139. }
  140.  
  141. function xmlDeveloperNodesToArray(node:Object):Array
  142. {
  143.     var a:Array = new Array();
  144.     var childNode:Object = node.firstChild;
  145.     while (childNode != null)
  146.     {
  147.         a.push({url: childNode.attributes.url, title: childNode.firstChild.nodeValue});
  148.         childNode = childNode.nextSibling;
  149.     }
  150.     return a;
  151. }
  152.  
  153. function xmlAttributesToObject(o:Object, node:Object):Object
  154. {
  155.     var a:Object = node.attributes;
  156.     for (var i in a)
  157.     {
  158.         o[i] = a[i];
  159.     }
  160.     return a;
  161. }
  162.  
  163. function xmlNodesToObject(o:Object, node:Object):Object
  164. {
  165.     var a:Object;
  166.     var childNode:Object = node.firstChild;
  167.     while (childNode != null)
  168.     {
  169.         o[childNode.nodeName] = childNode.firstChild.nodeValue;
  170.         
  171.         // This loop is for the URL attribute in the labels.
  172.         // Appends the attribute name to nodeName.
  173.         a = childNode.attributes;
  174.         for (var i in a)
  175.         {
  176.             o[childNode.nodeName + i] = a[i];
  177.         }
  178.         childNode = childNode.nextSibling;
  179.     }
  180.     return o;
  181. }
  182.  
  183. function xmlNodesToArray(node:XML):Array
  184. {
  185.     var a:Array = new Array();
  186.     var childNode:Object = node.firstChild;
  187.     while (childNode != null)
  188.     {
  189.         a.push(childNode.firstChild.nodeValue);
  190.         childNode = childNode.nextSibling;
  191.     }
  192.     return a;
  193. }
  194.  
  195. // Called after the shell and XML has been loaded and parsed.
  196. function onXMLParsed():Void
  197. {
  198.     detailView.swapDepths(9);
  199.     
  200.     
  201.     
  202.     // Set the global styles for the components.
  203.     _global.style.setStyle("fontSize", 10);
  204.     _global.style.setStyle("fontFamily" , "verdana");
  205.     _global.style.setStyle("color", 0xFFFFFF);
  206.  
  207.  
  208.     globalStyleFormat.textFont = "verdana";
  209.     globalStyleFormat.textSize = 11;
  210.     globalStyleFormat.selection = 0xCC3300;
  211. globalStyleFormat.scrollTrack = 0x666666;
  212. globalStyleFormat.face = 0x999999;
  213. globalStyleFormat.darkshadow = 0x000000;
  214. globalStyleFormat.shadow = 0x909090;
  215. globalStyleFormat.background = 0x4A99D3;
  216. globalStyleFormat.highlight = 0x666666;
  217. globalStyleFormat.highlight3D = 0x4D4D4D;
  218.     globalStyleFormat.applyChanges();
  219.  
  220.     // Set the text fields.
  221.     title.autoSize = "left";
  222.     title.htmlText = "<b>"+labels.title+"</b>";
  223.     
  224.     
  225.     
  226.     
  227.     
  228.     
  229.     
  230.     
  231.     // Create the listener objects for the CheckBoxes and the RadioButtons.
  232.     checkBoxListener = new Object();
  233.     checkBoxListener.container = this;
  234.     checkBoxListener.click = function(o:Object)
  235.     {
  236.         this.container.onClick_checkBox(o.target);
  237.     }
  238.     
  239.     
  240.     
  241.     // Set the beginning coordinates of the CheckBoxes.
  242.     var checkBoxYBegin:Number = 150;
  243.     var checkBoxXBegin:Number =  30;
  244.     var checkBoxWidth:Number = 110;
  245.     var checkBoxHeight:Number = 22;
  246.     
  247.     // Number of checkboxes per row.
  248.     var checkBoxesPerRow:Number = 4;
  249.     
  250.     // Horizontal spacing between each checkboxes.
  251.     var xSpacing:Number = 110;
  252.     
  253.  
  254.     var ySpacing:Number = 20;
  255.  
  256.     var checkBox, deltaX;
  257.  
  258.     regionCheckBoxArray = new Array();
  259.  
  260.  
  261.     j = 0;
  262.     for (var i in regions)
  263.     {
  264.         deltaX = j - Math.floor(j / checkBoxesPerRow) * checkBoxesPerRow;
  265.         checkBox = attachMovie("CheckBox", "checkBox" + zIndex++, zIndex,
  266.                                {_x: deltaX * (xSpacing) + checkBoxXBegin, _y: Math.floor(j / checkBoxesPerRow) * (ySpacing) + checkBoxYBegin});
  267.         checkBox.label = "  " + regions[i];    // This is to add spacing. Tried using textIndent but the end
  268.                                             // gets truncated. The spaces are removed below when filtering.
  269.         checkBox.addEventListener("click", checkBoxListener);
  270.         checkBox.setSize(checkBoxWidth, checkBoxHeight);
  271.         checkBox.data = {id: i, filter: "region"};
  272.         checkBox.selected = true;
  273.         checkBox._visible = true;            // Turn off the region CheckBoxes since industry is selected first.
  274.  
  275.         regionCheckBoxArray.push(checkBox);
  276.         
  277.         // Set the "view all" check box. This is used later for filtering.
  278.         if (i == "viewAll") viewAllRegionCheckBox = checkBox;
  279.  
  280.         j++;
  281.     }
  282.     
  283.     regionCheckBoxCount = regionCheckBoxArray.length;
  284.     
  285.     // Add the thumbs. ---------------------------------
  286.     var thumb;
  287.     var thumbXBegin:Number = 63;
  288.     var thumbYBegin:Number = 237;
  289.     var thumbsPerRow = 6;
  290.     xSpacing = 6;
  291.     ySpacing = 6;
  292.     
  293.     createEmptyMovieClip("ikony",10);
  294.     
  295.     thumbArray = new Array();
  296.     //CB.addItem("");
  297.     
  298.     for (var i = 0; i < siteCount; i++)
  299.     {
  300.         deltaX = i - Math.floor(i / thumbsPerRow) * thumbsPerRow;
  301.         thumb = ikony.attachMovie("thumb", "thumb" + i, zIndex++,
  302.                             {_x: deltaX * (thumb._width + xSpacing) + thumbXBegin,
  303.                              _y: Math.floor(i / thumbsPerRow) * (thumb._height + ySpacing) + thumbYBegin});
  304.         thumb.setData(i, sites[i]);
  305.         thumbArray.push(thumb);
  306.         
  307.                CB.addItem(sites[i].title,i); trace("dodaje "+i+" "+sites[i].title);
  308.  
  309.     }
  310.  
  311.     //CB.sortItemsBy("label", "ASC");
  312.  
  313.     _root.CB.onPress();
  314.     
  315.     _global.topThumb = thumb;
  316.  
  317.     // Move the rollover text to the top.
  318.     thumbRolloverText.swapDepths(11);
  319.     
  320.     // Set the labels in the detailView.
  321.     detailView.setLabels(labels, siteCount);
  322.     
  323.     showDetail(ikony.thumb0);
  324.  
  325.     cover.unloadMovie();
  326. }
  327.  
  328.  
  329.  
  330. // Filter the thumbs according to industry or region.
  331. function filterBy(filter:String):Void
  332. {
  333.  
  334.  
  335.  
  336.  
  337.     if (this["viewAll" + filter + "CheckBox"].selected)
  338.     {
  339.         for (var i = 0; i < siteCount; i++)        // Set the state of the thumbs.
  340.         {
  341.             thumbArray[i].setActive(true);
  342.         } 
  343.     }
  344.     else
  345.     {
  346.         var checkBox;
  347.         var checkBoxArray:Array = this[filter + "CheckBoxArray"];
  348.         var checkBoxCount:Number = checkBoxArray.length;
  349.         
  350.         // Passed to each thumb for filtering.
  351.         var checkedArray:Array = new Array();
  352.         
  353.         for (var i = 0; i < checkBoxCount; i++)    // Find out which CheckBoxes are checked.
  354.         {
  355.             checkBox = checkBoxArray[i];
  356.             if (checkBox.selected)
  357.             {
  358.                 checkedArray.push(checkBox.data.id);
  359.             }
  360.         }
  361.  
  362.         for (var i = 0; i < siteCount; i++)        // Filter the thumb.
  363.         {
  364.             thumbArray[i].filterBy(checkedArray, filter);
  365.         }
  366.     }
  367. }
  368.  
  369. function onClick_checkBox(cb:MovieClip):Void
  370. {
  371. _root.CB.removeAll(); _root.CB.onPress();
  372. //tt=_root.CB.getLength();trace(tt);
  373. //for (var i = 0; i < tt; i++){    trace(i+" usuwam:"+_root.CB.getItemAt(i).label); }
  374. //_root.CB.addItem("");
  375. //_root.CB.additem(title);
  376.  
  377.  
  378.  
  379.     var checkBoxArray:Array = this[cb.data.filter + "CheckBoxArray"];
  380.  
  381.     var checkBoxCount:Number = checkBoxArray.length;
  382.     if (cb == viewAllRegionCheckBox || cb == viewAllIndustryCheckBox)    // "View all" checkbox was selected.
  383.     {
  384.         var checkBox;
  385.         var isChecked:Boolean = cb.selected;
  386.  
  387.         for (var i = 0; i < checkBoxCount; i++)    // Set the state of the checkboxes.
  388.         {
  389.             checkBoxArray[i].selected = isChecked;
  390.         }
  391.         
  392.         for (var i = 0; i < siteCount; i++)        // Set the state of the thumbs.
  393.         {
  394.             thumbArray[i].setActive(isChecked);
  395.             if(isChecked) _root.CB.additem(thumbArray[i].title,thumbArray[i].index);
  396.         }
  397.     }
  398.     else
  399.     {
  400.         var isAllChecked:Boolean = true;
  401.         var viewAllCheckBox = this["viewAll" + cb.data.filter + "CheckBox"];
  402.         
  403.         // Check to see if all the CheckBoxes are selected.
  404.         for (var i = 0; i < checkBoxCount; i++) 
  405.         {
  406.             if (!checkBoxArray[i].selected && checkBoxArray[i] != viewAllCheckBox)
  407.             {
  408.                 isAllChecked = false;
  409.                 break;
  410.             }
  411.         }
  412.         
  413.         // All CheckBoxes are selected so check viewAllCheckBox.
  414.         if (isAllChecked)
  415.         {
  416.             viewAllCheckBox.selected = true;
  417.             onClick_checkBox(viewAllCheckBox);
  418.             return;
  419.         }
  420.         
  421.         // Not all selected so deselect viewAllCheckBox and then filter.
  422.         viewAllCheckBox.selected = false;
  423.         
  424.         filterBy(cb.data.filter);
  425.     }    
  426. }
  427.  
  428. function showDetail(th:MovieClip)
  429. {    detailView.blysk.play();
  430.     detailView.setData(sites[th.index]);
  431.     
  432. }
  433.  
  434.  
  435.  
  436. function onClose_detail():Void
  437. {
  438.     detailView._visible = false;
  439.     
  440. }
  441.  
  442. // Used for tracking on Macromedia.com.
  443. function sendOmnitureEvent(s:String):Void
  444. {
  445.     var s:String = s.split("'").join(""); // Remove apostrophes.
  446.                s = s.split("?").join(""); // Remove question marks.
  447.                s = s.split("&").join(""); // Remove ampersands.
  448.  
  449. }
  450.  
  451. // Create a global function for the TextLinks.
  452. _global.onRelease_textLink = function(link:MovieClip):Void
  453. {
  454.     getURL(link.url, "videoGallery");
  455. }
  456.  
  457. init();
  458.  
  459. stop();