Flex4 uint顏色值和16進位顏色互轉

來源:互聯網
上載者:User

前幾天遇到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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.