ColorPicker控件的fontFamily 样式学习.

示例:


代码:

<?xml version="1.0" encoding="utf-8"?>

<!-- http:///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中设置:

在ColorPicker控件中使用嵌入字体。_css<?xml version="1.0" encoding="utf-8"?>

在ColorPicker控件中使用嵌入字体。_css<!-- http:///2008/06/15/using-an-embedded-font-with-the-colorpicker-control-in-flex/ -->

在ColorPicker控件中使用嵌入字体。_css<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

在ColorPicker控件中使用嵌入字体。_css        layout="vertical"

在ColorPicker控件中使用嵌入字体。_css        verticalAlign="middle"

在ColorPicker控件中使用嵌入字体。_css        backgroundColor="white">

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

在ColorPicker控件中使用嵌入字体。_css    <mx:Style>

在ColorPicker控件中使用嵌入字体。_css        @font-face {

在ColorPicker控件中使用嵌入字体。_css            src: local("Base 02");

在ColorPicker控件中使用嵌入字体。_css            fontFamily: Base02Embedded;

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

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

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

在ColorPicker控件中使用嵌入字体。_css            fontFamily: Base02Embedded;

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

在ColorPicker控件中使用嵌入字体。_css    </mx:Style>

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

在ColorPicker控件中使用嵌入字体。_css    <mx:Script>

在ColorPicker控件中使用嵌入字体。_css        <![CDATA[

在ColorPicker控件中使用嵌入字体。_css            private function uintToHex(value:uint):String {

在ColorPicker控件中使用嵌入字体。_css                var prefix:String = "000000";

在ColorPicker控件中使用嵌入字体。_css                var str:String = String(prefix + value.toString(16));

在ColorPicker控件中使用嵌入字体。_css                return "#" + str.substr(-6).toUpperCase();

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

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

在ColorPicker控件中使用嵌入字体。_css    </mx:Script>

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

在ColorPicker控件中使用嵌入字体。_css    <mx:ApplicationControlBar dock="true">

在ColorPicker控件中使用嵌入字体。_css        <mx:ColorPicker id="colorPicker"

在ColorPicker控件中使用嵌入字体。_css                editable="false" />

在ColorPicker控件中使用嵌入字体。_css        <mx:Label id="lbl"

在ColorPicker控件中使用嵌入字体。_css                text="{uintToHex(colorPicker.selectedColor)}"

在ColorPicker控件中使用嵌入字体。_css                fontFamily="_typewriter"

在ColorPicker控件中使用嵌入字体。_css                fontSize="16" />

在ColorPicker控件中使用嵌入字体。_css    </mx:ApplicationControlBar>

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

在ColorPicker控件中使用嵌入字体。_css</mx:Application>

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


也可以通过AS的方法设置:

<?xml version="1.0" encoding="utf-8"?>

<!-- http:///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>