zoukankan      html  css  js  c++  java
  • [ActionScript 3.0] 自制简单拾色器

    colorBoard为库中绑定的影片剪辑,colorBoard中包含影片剪辑currColor,文本colorText,影片剪辑close;

    colorDot为库中绑定的影片剪辑,colorDot中包含影片剪辑dot,border;

      1 package 
      2 {
      3     import fl.motion.Color;
      4     import flash.display.MovieClip;
      5     import flash.display.Sprite;
      6     import flash.events.MouseEvent;
      7     import flash.geom.ColorTransform;
      8 
      9     /**
     10       * ...
     11       * @author Frost.Yen
     12       */
     13     public class ColorPicker extends Sprite
     14     {
     15         private var _colorBoard:MovieClip;
     16         private var _colorArr:Array = [0,0x333333,0x666666,0x999999,0xCCCCCC,0xFFFFFF,0xFF0000,0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF];
     17         private var _colorW:Number = 10;
     18         private var _prevBorder:MovieClip;
     19         public function ColorPicker()
     20         {
     21             creatColorBoard();
     22         }
     23 
     24         private function creatColorBoard():void
     25         {
     26             _colorBoard = new colorBoard  ;
     27             _colorBoard.x = 150;
     28             _colorBoard.y = 150;
     29             this.addChild(_colorBoard);
     30             for (var i:int = 0; i < 12; i++)
     31             {
     32                 var dot1:colorDot = new colorDot  ;
     33                 dot1.x = 0;
     34                 dot1.y = i * _colorW;
     35                 _colorBoard.addChild(dot1);
     36                 setColorTransform(dot1.dot,_colorArr[i]);
     37                 //trace(_colorArr[i]);
     38                 //trace(_colorArr[i].toString(16));
     39                 dot1.name = String(_colorArr[i]);
     40                 //trace(uint(dot1.name).toString(16), "---");
     41                 dot1.addEventListener(MouseEvent.CLICK,onColorClick);
     42             }
     43             for (var R = 0; R < 6; R++)
     44             {
     45                 for (var G = 0; G < 6; G++)
     46                 {
     47                     for (var B = 0; B < 6; B++)
     48                     {
     49                         var dot2:colorDot = new colorDot  ;
     50                         dot2.x = B * _colorW + R % 3 * 6 * _colorW + _colorW;
     51                         dot2.y = G * _colorW + Math.floor((R / 3)) * 6 * _colorW;
     52                         _colorBoard.addChild(dot2);
     53                         var color:uint = setRGB((0x33 * R),0x33 * B,0x33 * G);
     54                         setColorTransform(dot2.dot,color);
     55                         dot2.name = String(color);
     56                         dot2.addEventListener(MouseEvent.CLICK,onColorClick);
     57                     }
     58                 }
     59             }
     60             _prevBorder = _colorBoard.getChildByName("0") as MovieClip.border as MovieClip;
     61             _colorBoard.colorText.text = "#" + "000000";
     62             setColorTransform(_prevBorder,0xffffff);
     63             setColorTransform(_colorBoard.currColor,0x000000);
     64             _colorBoard.getChildByName("0").parent as MovieClip.setChildIndex(_colorBoard.getChildByName("0") as MovieClip,_colorBoard.getChildByName("0") as MovieClip.parent.numChildren - 1);
     65             _colorBoard.close.addEventListener(MouseEvent.CLICK,onCloseColorPicker);
     66         }
     67 
     68         private function onColorClick(e:MouseEvent):void
     69         {
     70 
     71 
     72             var color:String = uint(e.currentTarget.name).toString(16);
     73             color = color.length == 2 ? "0000" + color:color.length == 4 ? ("00" + color):color.length == 1 ? ("00000" + color):color;
     74             //trace(color,"+++");
     75             _colorBoard.colorText.text = "#" + color;
     76             setColorTransform(_colorBoard.currColor,uint(("0x" + color)));
     77             setColorTransform(e.currentTarget.border,0xffffff);
     78             setColorTransform(_prevBorder,0x000000);
     79             _prevBorder = e.currentTarget.border as MovieClip;
     80             e.currentTarget.parent as MovieClip.setChildIndex(e.currentTarget as MovieClip,e.currentTarget.parent.numChildren - 1);
     81         }
     82         /**
     83            * 改变影片剪辑颜色值
     84            * @param mc
     85            * @param color
     86            */
     87         private function setColorTransform(mc:MovieClip,color:uint):void
     88         {
     89             var ct:ColorTransform = new ColorTransform  ;
     90             ct.color = color;
     91             mc.transform.colorTransform = ct;
     92         }
     93         /**
     94            * 设置RGB
     95            * @param r
     96            * @param g
     97            * @param b
     98            * @return
     99            */
    100         private function setRGB(r:Number,g:Number,b:Number):Number
    101         {
    102             return r << 16 | g << 8 | b;
    103         }
    104 
    105         private function onCloseColorPicker(e:MouseEvent):void
    106         {
    107             trace("close");
    108         }
    109     }
    110 
    111 }
  • 相关阅读:
    centos7 双网口绑定
    centos docker 修改默认存储路径
    Django 操作已经存在的数据库
    package ‘RPMM’ is not available (for R version 3.6.0)
    关于tornado的raise gen.Retuen()
    tornodo学习之路
    关于微信小程序登录机制
    关于微信小程序更新机制
    过渡结束事件
    移动端动效
  • 原文地址:https://www.cnblogs.com/frost-yen/p/4450852.html
Copyright © 2011-2022 走看看