<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.styles.StyleManager;
private function toHex(item:Object):String {
var hex:String = Number(item).toString(16);
return ("00000" + hex.toUpperCase()).substr(-6);
}
private function button_click():void {
var colorInt:uint = StyleManager.getColorName(textInput.text);
if (colorInt == StyleManager.NOT_A_COLOR) {
swatch.setStyle("backgroundColor", StyleManager.NOT_A_COLOR);
lbl.text = "NOT A COLOR";
} else {
swatch.setStyle("backgroundColor", colorInt);
lbl.text = "#" + toHex(colorInt);
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Label text="Color name:" />
<mx:TextInput id="textInput" />
<mx:Button id="button"
label="Submit"
click="button_click()" />
</mx:ApplicationControlBar>
<mx:HBox>
<mx:Box id="swatch"
width="{lbl.height}"
height="{lbl.height}" />
<mx:Label id="lbl"
selectable="true"
fontFamily="_typewriter"
fontSize="64" />
</mx:HBox>
</mx:Application>