색값 변환 참고 샘플
가끔 색 변환하는 경우가 있었는데요 그때 그때 참고 할려고 만들었습니다
HEX에서 RGB값으로 RGB값을 HEX값으로 변환할때 참고
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:Style>
global {
fontSize : 11;
color : #6A6A6A;
}
Application {
backgroundGradientColors : #000000, #6A6A6A;
}
.show {
borderStyle : solid;
borderThickness : 0.5;
borderColor : #CECECE;
cornerRadius : 8;
backgroundColor : #FFFFFF;
}
.bxStyle {
borderStyle : solid;
borderThickness : 0;
cornerRadius : 8;
backgroundColor : #FFFFFF;
paddingTop : 10;
paddingLeft : 10;
paddingRight : 10;
paddingBottom : 10;
}
.txi {
backgroundColor : #2e2929;
textAlign : center;
color : #FFFFFF;
borderStyle : solid;
borderThickness : 0;
cornerRadius : 8;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.events.SliderEvent;
private function init():void
{
configure();
}
private function configure():void
{
var setColor:uint = show.getStyle("backgroundColor");
var al:uint = (setColor >> 24) & 0xFF;
var rc:uint = (setColor >> 16) & 0xFF;
var gc:uint = (setColor >> 8) & 0xFF;
var bc:uint = setColor & 0xFF;
rColor.value = rc;
gColor.value = gc;
bColor.value = bc;
show.setStyle("backgroundColor", setColor);
configureTxis();
}
/**
* TextInput 설정
*/
private function configureTxis():void
{
rTxi.maxChars = 3;
gTxi.maxChars = 3;
bTxi.maxChars = 3;
allTxi.maxChars = 6;
rTxi.restrict = "0-9";
gTxi.restrict = "0-9";
bTxi.restrict = "0-9";
allTxi.restrict = "0-9,A-z";
}
/**
* Slider로 변경
*/
private function colorChangeHandler(evt:SliderEvent=null):void
{
rTxi.text = rColor.value.toString();
gTxi.text = gColor.value.toString();
bTxi.text = bColor.value.toString();
allTxi.text = setLen(rColor.value.toString(16),2) +
setLen(gColor.value.toString(16),2) +
setLen(bColor.value.toString(16),2);
show.setStyle("backgroundColor","#"+allTxi.text);
}
/**
* RGB 입력으로 변경
*/
private function txiChangeHandler(evt:Event=null):void
{
if (Number(rTxi.text) > 255)
rTxi.text = "255";
if (Number(gTxi.text) > 255)
gTxi.text = "255";
if (Number(bTxi.text) > 255)
bTxi.text = "255";
rColor.value = Number(rTxi.text);
gColor.value = Number(gTxi.text);
bColor.value = Number(bTxi.text);
colorChangeHandler();
}
/**
* 컬러 입력으로 변경
*/
private function allTxiChangeHandler(evt:Event):void
{
if (allTxi.text.length !=6 )
return;
var tmp:String = allTxi.text;
rTxi.text =
String( parseInt( allTxi.text.substr(0,2),16 ) );
gTxi.text =
String( parseInt( allTxi.text.substr(2,2),16 ) );
bTxi.text =
String( parseInt( allTxi.text.substr(4,2),16 ) );
txiChangeHandler();
}
/**
* 자릿수 설정
*/
private function setLen(str:String, len:int):String
{
if (str.length > len)
return str.substr(0,len);
var forLen:int = len - str.length;
for (var i:int=0; i<forLen; i++)
{
str = "0" + str;
}
return str;
}
]]>
</mx:Script>
<mx:Box width="220" height="180" styleName="bxStyle">
<mx:Container id="show" width="100%" height="100%" styleName="show"/>
<!--<mx:HSlider id="aColor" width="100%" minimum="0" maximum="255"
change="colorChangeHandler(event)" liveDragging="true" snapInterval="1"/-->
<mx:HSlider id="rColor" width="100%" minimum="0" maximum="255"
change="colorChangeHandler(event)" liveDragging="true" snapInterval="1"/>
<mx:HSlider id="gColor" width="100%" minimum="0" maximum="255"
change="colorChangeHandler(event)" liveDragging="true" snapInterval="1"/>
<mx:HSlider id="bColor" width="100%" minimum="0" maximum="255"
change="colorChangeHandler(event)" liveDragging="true" snapInterval="1"/>
<mx:HBox width="100%">
<mx:TextInput id="rTxi" width="35" styleName="txi" enter="txiChangeHandler(event)"/>
<mx:TextInput id="gTxi" width="35" styleName="txi" enter="txiChangeHandler(event)"/>
<mx:TextInput id="bTxi" width="35" styleName="txi" enter="txiChangeHandler(event)"/>
<mx:TextInput id="allTxi" width="100%" styleName="txi" enter="allTxiChangeHandler(event)"/>
</mx:HBox>
</mx:Box>
</mx:Application> |