小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

在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>

posted on 2008-06-17 10:42  『小小菜鸟』  阅读(749)  评论(1编辑  收藏  举报