前幾天遇到Flex需要用uint來表示顏色值的問題,
在網上摸索了半天寫出了如下轉換的代碼,
希望能對需要的朋友有所協助!
<?xml version="1.0" encoding="utf-8"?><br /><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="433" width="397"><br /><mx:Script><br /><!--[CDATA[<br />private function convertUintToString():void<br />{<br />var xx:uint = new uint(uint_txt.text);<br />result_hexadecimal.text = xx.toString(16);<br />}<br />private function convertStringToUint():void<br />{<br />var colorString:String = "0x" + hexadecimal_txt.text;<br />var colorUint:uint = mx.core.Singleton.getInstance("mx.styles::IStyleManager2").getColorName( colorString );<br />result_uint.text = colorUint.toString();<br />}<br />private function setColor():void<br />{<br />result_final.text = pcolor.selectedColor.toString();<br />}<br />]]--><br /></mx:Script><br /><mx:Label text="uint和16進位顏色互轉" color="#F81E08" fontWeight="bold" fontSize="17"/><br /><mx:Label text=" 請輸入uint值:"/><br /><mx:TextInput id="uint_txt"/><br /><mx:Label text="結果為(16進位顏色字串):"/><br /><mx:TextInput id="result_hexadecimal"/><br /><mx:Button label="確定" click="convertUintToString()"/><br /><mx:Label text=" 請輸入16進位顏色字串:"/><br /><mx:TextInput id="hexadecimal_txt"/><!--text="#{pcolor.selectedColor.toString(16)}"--><br /><mx:Label text="結果為(uint):"/><br /><mx:TextInput id="result_uint"/><br /><mx:Button label="確定" click="convertStringToUint()"/><br /><mx:Label text="最直接的16進位顏色轉uint:"/><br /><mx:ColorPicker id="pcolor" change="setColor()"/><br /><mx:TextInput id="result_final"/><br /></mx:Application>