在ColorPicker控件中使用嵌入字体。

ColorPicker控件的fontFamily 样式学习.
示例:



代码:

<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2008/06/15/using-an-embedded-font-with-the-colorpicker-control-in-flex/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white" >

    
< mx:Style >
        @font-face {
            src: local("Base 02");
            fontFamily: Base02Embedded;
        }
    
</ mx:Style >

    
< mx:Script >
        
<![CDATA[
            private function uintToHex(value:uint):String {
                var prefix:String = "000000";
                var str:String = String(prefix + value.toString(16));
                return "#" + str.substr(-6).toUpperCase();
            }
        
]]>
    
</ mx:Script >

    
< mx:ApplicationControlBar  dock ="true" >
        
< mx:ColorPicker  id ="colorPicker"
                fontFamily
="Base02Embedded"
                editable
="false"   />
        
< mx:Label  id ="lbl"
                text
=" {uintToHex(colorPicker.selectedColor)} "
                fontFamily
="_typewriter"
                fontSize
="16"   />
    
</ mx:ApplicationControlBar >

</ mx:Application >

也可以在CSS中设置:
<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2008/06/15/using-an-embedded-font-with-the-colorpicker-control-in-flex/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white" >

    
< mx:Style >
        @font-face {
            src: local("Base 02");
            fontFamily: Base02Embedded;
        }

        ColorPicker {
            fontFamily: Base02Embedded;
        }
    
</ mx:Style >

    
< mx:Script >
        
<![CDATA[
            private function uintToHex(value:uint):String {
                var prefix:String = "000000";
                var str:String = String(prefix + value.toString(16));
                return "#" + str.substr(-6).toUpperCase();
            }
        
]]>
    
</ mx:Script >

    
< mx:ApplicationControlBar  dock ="true" >
        
< mx:ColorPicker  id ="colorPicker"
                editable
="false"   />
        
< mx:Label  id ="lbl"
                text
=" {uintToHex(colorPicker.selectedColor)} "
                fontFamily
="_typewriter"
                fontSize
="16"   />
    
</ mx:ApplicationControlBar >

</ mx:Application >

也可以通过AS的方法设置:
<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2008/06/15/using-an-embedded-font-with-the-colorpicker-control-in-flex/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init();" >

    
< mx:Style >
        @font-face {
            src: local("Base 02");
            fontFamily: Base02Embedded;
        }
    
</ mx:Style >

    
< mx:Script >
        
<![CDATA[
            private function init():void {
                colorPicker.setStyle("fontFamily", "Base02Embedded");
            }

            private function uintToHex(value:uint):String {
                var prefix:String = "000000";
                var str:String = String(prefix + value.toString(16));
                return "#" + str.substr(-6).toUpperCase();
            }
        
]]>
    
</ mx:Script >

    
< mx:ApplicationControlBar  dock ="true" >
        
< mx:ColorPicker  id ="colorPicker"
                editable
="false"
                initialize
="init();"   />
        
< mx:Label  id ="lbl"
                text
=" {uintToHex(colorPicker.selectedColor)} "
                fontFamily
="_typewriter"
                fontSize
="16"   />
    
</ mx:ApplicationControlBar >

</ mx:Application >

你可能感兴趣的:(color)