Flex中通过设置嵌入字体以及替换默认Skin自定义Button风格的例子

By Minidxer | August 16, 2008

接下来的例子演示了Flex中通过设置嵌入字体以及替换默认Skin,自定义Button风格。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.     applicationComplete="init()"
  4.     layout="vertical"
  5.     verticalAlign="middle"
  6.     backgroundColor="white">
  7.  
  8.     <mx:String id="fileName" />
  9.     <mx:String id="fileSize" />
  10.  
  11.     <mx:Script>
  12.         <![CDATA[
  13.             private function init():void {
  14.                 var appInfo:LoaderInfo = Application.application.loaderInfo;
  15.                 /* Just grab the filename from the SWF URL. */
  16.                 fileName = (appInfo.url).split("/").pop();
  17.                 /* Convert bytes to kilobytes. */
  18.                 fileSize = (appInfo.bytesTotal / 1024).toFixed(2);
  19.             }
  20.         ]]>
  21.     </mx:Script>
  22.  
  23.     <mx:Style>
  24.         @font-face{
  25.             src: url("./fonts/base02.ttf");
  26.             fontFamily: "Base02";
  27.         }
  28.  
  29.         .myButtonStyle {
  30.             embedFonts: true;
  31.             fontFamily: Base02;
  32.             fontWeight: normal;
  33.             fontSize: 24;
  34.             cornerRadius: 0;
  35.             letterSpacing: 4;
  36.             textRollOverColor: red;
  37.             skin: ClassReference(null);
  38.             icon: Embed(source="./assets/iconInstall.png");
  39.         }
  40.     </mx:Style>
  41.  
  42.     <mx:ApplicationControlBar id="applicationControlBar" dock="true">
  43.         <mx:Label id="info" text="{fileName} ({fileSize}kb)" />
  44.     </mx:ApplicationControlBar>
  45.  
  46.     <mx:Button id="btn" label="{btn.getStyle('fontFamily')}" styleName="myButtonStyle" />
  47.  
  48. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | Tags: , , ,

Related Post

One comment | Add One

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads