Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.conceptualideas.videoplayer.utils {
  2.     import com.conceptualideas.utils.ColorTools;
  3.     import flash.display.DisplayObject;
  4.     import com.conceptualideas.videoplayer.utils.PlayerUtils;
  5.     import flash.display.Sprite;
  6.     import flash.geom.ColorTransform;
  7.    
  8.     /**
  9.      * ...
  10.      * @author Conceptual Ideas
  11.      */
  12.     public class Colorer {
  13.        
  14.         public function Colorer() {
  15.            
  16.         }
  17.         public static function recursiveColor(base:DisplayObject, colors:Object):void {
  18.            
  19.             var colorElement:DisplayObject
  20.                 for (var section:String in colors) {
  21.                     for (var element:String in colors[section]) {
  22.                         if (colors[section][element] == "default" ) { continue };
  23.                            
  24.                         colorElement = findElement(base, section, element);
  25.                        
  26.                         if (colorElement) {
  27.                             setColorTransForm(colorElement, colors[section][element]);
  28.                         }
  29.                        
  30.                     }
  31.                    
  32.                 }  
  33.            
  34.            
  35.         }
  36.        
  37.         public static function recursiveAlpha(base:DisplayObject, alphas:Object):void {
  38.                 var alphaElement:DisplayObject
  39.                 for (var section:String in alphas) {
  40.                     for (var element:String in alphas[section]) {
  41.                         if (alphas[section][element] == "default" ) { continue };
  42.                            
  43.                         alphaElement = findElement(base, section, element);
  44.                         if (alphaElement) {
  45.                            
  46.                             setAlpha(alphaElement, alphas[section][element]);
  47.                         }
  48.                        
  49.                     }
  50.                    
  51.                 }  
  52.         }
  53.         private static function findElement(base:Object, section:String, element:String):DisplayObject {
  54.            
  55.                     var found:DisplayObject;
  56.                        
  57.                         try {
  58.                             found = base[section][element];
  59.                             if(section!="time"){
  60.                                 if (base[section][element] && base[section][element]["overlay"]) { // Check to see if we have an overlay object, used for grey gradients
  61.                                    
  62.                                     found = base[section][element]["overlay"];
  63.                                 }else if (base[section][section + "_slider"] &&
  64.                                     (base[section][section + "_slider"][element]
  65.                                         || base[section][section + "_slider"][element]["overlay"])) {
  66.                                    
  67.                                     found = base[section][section + "_slider"][element]["overlay"]||base[section][section + "_slider"][element]
  68.                                        
  69.                                 }
  70.                             }
  71.                            
  72.                        
  73.                         }catch (e:Error) { };
  74.             return found;
  75.         }
  76.        
  77.         public static function colorPlayButton(obj:DisplayObject, scheme:Object,state:String):void {
  78.            
  79.             var ctf:ColorTransform = new ColorTransform();
  80.        
  81.             var baseColor:uint = scheme.colors.icons.playicon.base;
  82.            
  83.             var innerColor:uint = scheme.colors.icons.playicon.inner;
  84.             if (!innerColor) innerColor = 0x000000;
  85.          
  86.             var isBright:Boolean = ColorTools.isBright(baseColor);
  87.             if(state=="up"){
  88.            
  89.             if (isBright){
  90.                
  91.                 if (obj["background"]) {
  92.                     setColorTransForm(obj["background"], ColorTools.darkenColor(baseColor, 10));
  93.                    
  94.                 }
  95.              
  96.                
  97.                 if (obj["outlineShadow"]) {            
  98.                   setColorTransForm(obj["outlineShadow"], ColorTools.darkenColor(baseColor, 40));
  99.                   obj["outlineShadow"].alpha = .3;
  100.                 }
  101.                
  102.                 if (obj["outlineBorder"]) {
  103.                    
  104.                     setColorTransForm(obj["outlineBorder"], ColorTools.darkenColor(baseColor, 100));
  105.                  
  106.                 }
  107.                
  108.             } else {              
  109.                 if (obj["background"]) {               
  110.                     setColorTransForm(obj["background"], ColorTools.lightenColor(baseColor, 40));
  111.                    
  112.                 }
  113.                
  114.                 if (obj["fill"]) {
  115.                    
  116.                     obj["fill"].transform.colorTransform = new ColorTransform();
  117.                     obj["fill"].transform.colorTransform.alphaMultiplier=.4
  118.                 }
  119.              
  120.                 if (obj["outlineShadow"]) {
  121.                      
  122.                     setColorTransForm(obj["outlineShadow"], ColorTools.lightenColor(baseColor, 15));
  123.                     setAlpha(obj["outlineShadow"], 30);
  124.                    
  125.                 }
  126.                
  127.                 if (obj["outlineBorder"]) {
  128.                    
  129.                     setColorTransForm(  obj["outlineBorder"],ColorTools.darkenColor(baseColor, 30))
  130.                    
  131.                 }
  132.                
  133.             }
  134.                
  135.                
  136.                 setColorTransForm(obj["icon"], innerColor);
  137.             }else {
  138.            
  139.                 if (obj["background"]) {
  140.                    
  141.                     setColorTransForm( obj["background"], ColorTools.lightenColor(baseColor, (isBright)?40:100));
  142.                    
  143.                 };
  144.                 if (obj["outlineBorder"]) {
  145.                     var borderColor:uint = obj["outlineBorder"].transform.colorTransform.color;
  146.                     setColorTransForm( obj["outlineBorder"], ColorTools.lightenColor(borderColor, 20));
  147.                    
  148.                 }
  149.             }
  150.            
  151.         }
  152.         protected function setGradientFill(obj:Sprite,colors:Array,alphas:Array,gradientSettings:Object,matrixSettings:Object,ratios:Array=null):void {
  153.             PlayerUtils.setGradientFill(obj, colors, alphas, gradientSettings, matrixSettings,ratios);
  154.         }
  155.         /**
  156.          * Sets the color of the object
  157.          * @param   obj <DisplayObject>
  158.          * @param   color <unit>
  159.          */
  160.         public static function setColorTransForm(obj:DisplayObject, color:uint,blendMode:String=null):void {
  161.             if (obj != null) {
  162.                
  163.                 PlayerUtils.setColorTransForm(obj, color);
  164.                 if (blendMode) {
  165.                     obj.blendMode = blendMode;
  166.                 }
  167.             }
  168.         }
  169.         protected static function setAlpha(obj:DisplayObject, alpha:Number):void {
  170.             alpha = (alpha > 1)?alpha / 100:alpha;
  171.             obj.alpha = alpha;
  172.            
  173.         }
  174.        
  175.        
  176.     }
  177.    
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement