/**
* Copyright Thy ( http://wonderfl.net/user/Thy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vE2n
*/
package
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
/**
* ...
* @author Thi
*/
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private var i:Cor = new Cor()
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var G:Graphics = shape.graphics
G.drawRect(0,0,stage.stageWidth, stage.stageHeight)
G = null
addChild(shape)
addChild(i)
addEventListener(Event.ENTER_FRAME, ef)
}
private var shape:Shape = new Shape()
private function ef(e:Event = null):void
{
if (i.update)
{
shape.opaqueBackground = i.cor
i.update = false
}
}
}
}
//package
//{
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Matrix;
/**
* ...
* @author Thi
*/
/*public*/ class Cor extends Sprite
{
private var colunaR:Sprite = new Sprite()
private var colunaG:Sprite = new Sprite()
private var colunaB:Sprite = new Sprite()
private var sliderR:Sprite = new Sprite()
private var sliderG:Sprite = new Sprite()
private var sliderB:Sprite = new Sprite()
public var cor:uint
public var R:uint
public var G:uint
public var B:uint
public function Cor(cor:uint = 0):void
{
this.cor = cor
this.R = uint(cor >> 16 & 0xFF)
this.G = uint(cor >> 8 & 0xFF)
this.B = uint(cor & 0xFF)
addEventListener(Event.ADDED_TO_STAGE, init);
}
private var g:Graphics
private var M:Matrix
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
trace(R,G,B)
M = new Matrix()
M.createGradientBox(255,10)
draw()
g = sliderR.graphics
g.lineStyle(0, 0xFFFFFF)
g.moveTo(0,1)
g.lineTo(0, 10)
g = sliderG.graphics
g.lineStyle(0, 0xFFFFFF)
g.moveTo(0,1)
g.lineTo(0, 10)
g = sliderB.graphics
g.lineStyle(0, 0xFFFFFF)
g.moveTo(0,1)
g.lineTo(0, 10)
this.addChild(colunaR)
this.addChild(colunaG)
this.addChild(colunaB)
this.addChild(sliderR)
this.addChild(sliderG)
this.addChild(sliderB)
sliderG.y = 20
sliderB.y = 40
sliderR.blendMode = BlendMode.INVERT
sliderG.blendMode = BlendMode.INVERT
sliderB.blendMode = BlendMode.INVERT
colunaR.addEventListener(MouseEvent.MOUSE_DOWN, down)
colunaG.addEventListener(MouseEvent.MOUSE_DOWN, down)
colunaB.addEventListener(MouseEvent.MOUSE_DOWN, down)
this.addEventListener(MouseEvent.MOUSE_UP, up)
}
private function draw():void
{
g = colunaR.graphics
g.lineStyle(1, 0)
g.beginGradientFill("linear", [uint(0x00<<16 | G<<8 | B), uint(0xFF<<16 | G<<8 | B)], [1,1], [0,255], M)
g.drawRect(0, 0, 255, 10)
g.endFill()
g = colunaG.graphics
g.lineStyle(1, 0)
g.beginGradientFill("linear", [uint(R<<16 | 0x00<<8 | B), uint(R<<16 | 0xFF<<8 | B)], [1,1], [0,255], M)
g.drawRect(0, 20, 255, 10)
g.endFill()
g = colunaB.graphics
g.lineStyle(1, 0)
g.beginGradientFill("linear", [uint(R<<16 | G<<8 | 0x00), uint(R<<16 | G<<8 | 0xFF)], [1,1], [0,255], M)
g.drawRect(0, 40, 255, 10)
g.endFill()
}
private var DOWN:int = 0
private function down(e:MouseEvent):void
{
if (DOWN == 1)
{
colunaR.removeEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (DOWN == 2)
{
colunaG.removeEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (DOWN == 3)
{
colunaB.removeEventListener(MouseEvent.MOUSE_MOVE, move)
}
if (e.target == colunaR)
{
DOWN = 1
colunaR.addEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (e.target == colunaG)
{
DOWN = 2
colunaG.addEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (e.target == colunaB)
{
DOWN = 3
colunaB.addEventListener(MouseEvent.MOUSE_MOVE, move)
}
}
private function up(e:MouseEvent = null):void
{
if (DOWN == 1)
{
colunaR.removeEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (DOWN == 2)
{
colunaG.removeEventListener(MouseEvent.MOUSE_MOVE, move)
} else if (DOWN == 3)
{
colunaB.removeEventListener(MouseEvent.MOUSE_MOVE, move)
}
DOWN = 0
}
public var update:Boolean
private function move(e:MouseEvent = null):void
{
if (DOWN == 1)
{
sliderR.x = R = mouseX > 255? 255 : mouseX
} else if (DOWN == 2)
{
sliderG.x = G = mouseX > 255? 255 : mouseX
} else if (DOWN == 3)
{
sliderB.x = B = mouseX > 255? 255 : mouseX
}
cor = uint(R<<16 | G<<8 | B)
trace("update")
update = true
draw()
}
}
//}