Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var hexcolor;
  3. var HexColor:String;
  4.  
  5. function ConfigOutline ():Sprite
  6. {
  7.         var Popup = new Panel();
  8.         var colorPickerOver:Boolean = false;
  9.         Popup.OutlineHex.restrict = "0-9 a-f A-F";
  10.         Popup.text1.visible = false;
  11.         Popup.switch2.visible = false;
  12.         Popup.SubmitColor.addEventListener(MouseEvent.CLICK, submitHandler);
  13.         Popup.colorPicker.addEventListener(MouseEvent.MOUSE_MOVE, colorMovedHandler);
  14.         Popup.colorPicker.addEventListener(MouseEvent.CLICK, colorPickedHandler);
  15.         Popup.switch1.addEventListener(MouseEvent.CLICK, switch1Handler);
  16.         function submitHandler ()
  17.         {
  18.                 hexcolor = Number("0x" + Popup.OutlineHex.text.substr(0,6));
  19.                 HexColor = Popup.OutlineHex.text.substr(0,6);
  20.                _ctrl.setMemory("ColorConfig", sendColor(HexColor));
  21.                _ctrl.sendMessage("ChangeColor", hexcolor);
  22.         }
  23.         function sendColor (hexcolor:String):Object
  24.         {
  25.                var Hexcolor:Object;
  26.                Hexcolor = hexcolor;
  27.                return Hexcolor;
  28.         }
  29.         //The switch handler is me testing out having more than one panel on it
  30.         function switch1Handler ()
  31.         {
  32.             Popup.switch1.removeEventListener(MouseEvent.CLICK, switch1Handler);
  33.             Popup.SubmitColor.removeEventListener(MouseEvent.CLICK, submitHandler);
  34.             Popup.colorPicker.removeEventListener(MouseEvent.MOUSE_MOVE, colorMovedHandler);
  35.             Popup.colorPicker.removeEventListener(MouseEvent.CLICK, colorPickedHandler);
  36.             Popup.text1.visible = true;
  37.             Popup.switch2.visible = true;
  38.             Popup.colorPicker.visible = false;
  39.             Popup.switch1.visible = false;
  40.             Popup.OutlineHex.visible = false;
  41.             Popup.SubmitColor.visible = false;
  42.             Popup.switch2.addEventListener(MouseEvent.CLICK, switch2Handler);
  43.         }
  44.         function switch2Handler ()
  45.         {
  46.             Popup.colorPicker.addEventListener(MouseEvent.MOUSE_MOVE, colorMovedHandler);
  47.             Popup.colorPicker.addEventListener(MouseEvent.CLICK, colorPickedHandler);
  48.             Popup.switch1.addEventListener(MouseEvent.CLICK, switch1Handler);
  49.             Popup.SubmitColor.addEventListener(MouseEvent.CLICK, submitHandler);
  50.             Popup.text1.visible = false;
  51.             Popup.switch2.visible = false;
  52.             Popup.colorPicker.visible = true;
  53.             Popup.switch1.visible = true;
  54.             Popup.OutlineHex.visible = true;
  55.             Popup.SubmitColor.visible = true;
  56.             Popup.switch2.removeEventListener(MouseEvent.CLICK, switch2Handler);
  57.         }
  58.         //this is from config tut
  59.         function getBitmapData (src :DisplayObject) :BitmapData
  60.         {
  61.             var bounds :Rectangle = src.getBounds(src);
  62.             var bd :BitmapData = new BitmapData(bounds.width, bounds.height, true, 0);
  63.             bd.draw(src, new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y));
  64.             return bd;
  65.         }
  66.         //this is from the config tut
  67.         function setSwatchColor (color :uint) :void
  68.         {
  69.             var _swatch:Shape = new Shape();
  70.             _swatch.graphics.beginFill(color);
  71.             _swatch.graphics.drawRect(265, 225, 30, 30);
  72.             _swatch.graphics.endFill();
  73.         }
  74.         //This is supposed to look at the color when it's moving
  75.         function colorMovedHandler (e:MouseEvent)
  76.         {
  77.             var bm :BitmapData = getBitmapData(Popup.colorPicker);
  78.             setSwatchColor(bm.getPixel(e.localX, e.localY));
  79.         }
  80.         //this will submit my color once they click
  81.         function colorPickedHandler (e:MouseEvent)
  82.         {
  83.             var bm :BitmapData = getBitmapData(Popup.colorPicker);
  84.             var colorPicked:uint;
  85.             colorPicked = bm.getPixel(e.localX, e.localY);
  86.             HexColor = colorPicked.toString(16);
  87.             hexcolor = Number("0x" + HexColor);
  88.             _ctrl.setMemory("ColorConfig", sendColor(HexColor));
  89.             _ctrl.sendMessage("ChangeColor", hexcolor);
  90.         }
  91.         _ctrl.showPopup("Config Color", Popup, 300, 300, 0x000000, 1);
  92.         return Popup;
  93. }
  94. _ctrl.registerCustomConfig(ConfigOutline);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement