2010年10月21日   Flex   8,467 次浏览

       这是用flex4做的一个字体对话框,跟windows的notepad的字体对话框类似,在这个对话框中选择字体,字形,字号就可以根据选择的字体样式改变文字的样式。里面包含了很多flex的内容,比如说得到弹出框的父对象,三目运算符的使用等,这是一个titleWindow,在主页面中只要使用PopUpManager.addPopUp()弹出就可以了,代码如下:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:TitleWindow xmlns:fx=”http://ns.adobe.com/mxml/2009
      xmlns:s=”library://ns.adobe.com/flex/spark”
      xmlns:mx=”library://ns.adobe.com/flex/mx” width=”466″ height=”226″
      close=”onClose()”>
 <s:layout>
  <s:BasicLayout/>
 </s:layout>
 <fx:Declarations>
  <!– 将非可视元素(例如服务、值对象)放在此处 –>
 </fx:Declarations>
 <fx:Style>
  @namespace s “library://ns.adobe.com/flex/spark”;
  @namespace mx “library://ns.adobe.com/flex/mx”;
  global{
   font-size:12;
   font-family:宋体;
  }
 </fx:Style>
 <fx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.managers.PopUpManager;
   
   [Bindable]
   public var fontfamily:String;
   
   [Bindable]
   public var fonts:String;
   
   [Bindable]
   public var fontsizes:String ;
   
   private var fontFamily:ArrayCollection = new ArrayCollection(
    [“宋体”,”Arial”,”隶书”,”黑体”,”新宋体”,”华文彩云”]);
   
   private var font:ArrayCollection = new ArrayCollection(
    [“常规”,”斜体”,”粗体”,”粗斜体”]);
   
   private var fontsize:ArrayCollection = new ArrayCollection(
    [“8″,”9″,”10″,”11″,”12″,”14″,”16″,”18″,”36”]);
   
   private function onClose():void{
    PopUpManager.removePopUp(this);
   }
   
   private function getFont():void{
    fontFamilyInput.text  = fontFamilyList.selectedItem;
       fontInput.text = fontList.selectedItem;
    fontSizeInput.text = fontsizeList.selectedItem;
   }
   
   //确定后得到字体样式
   private function getAllFont():void{
      fontfamily = fontFamilyInput.text == “” ? “宋体”: fontFamilyInput.text ;
      fonts = fontInput.text == “” ? “常规”:fontInput.text;
      fontsizes = fontSizeInput.text == “” ? “12”:fontSizeInput.text;
    
      this.parentDocument.ta.setStyle(“fontFamily”,fontfamily);
      this.parentDocument.ta.setStyle(“fontSize”,fontsizes);
     
      if(fonts == “斜体”){
       this.parentDocument.ta.setStyle(“fontStyle”,”italic”);
      }else if(fonts == “粗体”){
       this.parentDocument.ta.setStyle(“fontWeight”,”bold”);
      }else if(fonts == “粗斜体”){
       this.parentDocument.ta.setStyle(“fontStyle”,”italic”);
       this.parentDocument.ta.setStyle(“fontWeight”,”bold”);
      }else{
       this.parentDocument.ta.setStyle(“fontWeight”,”normal”);
      }
     
      //关闭弹出框
      PopUpManager.removePopUp(this);
   }
   
   //取消按钮
   private function cancel():void{
    PopUpManager.removePopUp(this);
   }
  ]]>
 </fx:Script>
 <s:Label x=”10″ y=”8″ text=”字体:”  />
 <s:Label x=”163″ y=”14″ text=”字形:” />
 <s:Label x=”273″ y=”14″ text=”大小:”/>
 <s:TextInput x=”6″ y=”35″ width=”127″ height=”20″ id=”fontFamilyInput”/>
 <s:List id=”fontFamilyList” x=”8″ y=”69″ width=”125″ height=”99″ dataProvider=”{fontFamily}” click=”getFont()” ></s:List>
 <s:TextInput x=”161″ y=”35″ width=”76″ height=”20″ id=”fontInput”/>
 <s:TextInput x=”272″ y=”31″ width=”43″ height=”20″ id=”fontSizeInput”/>
 <s:List id=”fontList” x=”161″ y=”75″ width=”76″ height=”93″ dataProvider=”{font}”  click=”getFont()” ></s:List>
 <s:List id=”fontsizeList” x=”277″ y=”72″ height=”96″ width=”47″ dataProvider=”{fontsize}”  click=”getFont()”></s:List>
 <s:Button x=”356″ y=”31″ label=”确定” click=”getAllFont()” />
 <s:Button x=”355″ y=”73″ label=”取消” click=”cancel();”/>
</s:TitleWindow>

*注:ta是指主页面中的textArea,通过this.parentDocument就可以得到父对象。

赞 赏
申明:除非注明,本站文章均为原创,转载请以链接形式标明本文地址。 如有问题,请于一周内与本站联系,本站将在第一时间对相关内容进行处理。
本文地址: http://www.yyjjssnn.cn/articles/603.html
相关阅读: Flex, flex字体, flex字体对话框

>>> Hello World <<<

这篇内容是否帮助到你了呢?

如果你有任何疑问或有建议留给其他朋友,都可以给我留言。

:wink: :twisted: :surprised: :smile: :smile9: :smile8: :smile7: :smile6: :smile5: :smile56: :smile55: :smile54: :smile53: :smile52: :smile51: :smile50: :smile4: :smile49: :smile48: :smile47: :smile46: :smile45: :smile44: :smile43: :smile42: :smile41: :smile40: :smile3: :smile39: :smile38: :smile37: :smile36: :smile35: :smile34: :smile33: :smile32: :smile31: :smile30: :smile2: :smile29: :smile28: :smile27: :smile26: :smile25: :smile24: :smile23: :smile22: :smile21: :smile20: :smile1: :smile19: :smile18: :smile17: :smile16: :smile15: :smile14: :smile13: :smile12: :smile11: :smile10: :smile0: :sad: :rolleyes1: :redface: :razz: :question: :neutral: :mrgreen: :mad: :lol: :idea: :exclaim: :evil: :eek: :cry: :cool: :confused: :biggrin: :arrow:

友情链接: 程序员刘杨 刘杨
Copyright 2003~2018 保留所有权利 | 网站地图
备案号:湘ICP备14001005号-2

湘公网安备 43011102001322号