Flex Gumbo中如何格式化显示TextArea选中的文本的例子

By Minidxer | September 9, 2009

接下来的例子演示了Flex Gumbo中如何通过调用setSelectionFormat()函数,格式化显示TextArea选中的文本。

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


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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="Spark_TextArea_setSelectionFormat_test"
  3.                xmlns:fx="http://ns.adobe.com/mxml/2009"
  4.                xmlns:s="library://ns.adobe.com/flex/spark"
  5.                xmlns:mx="library://ns.adobe.com/flex/halo">
  6.  
  7.     <fx:Script>
  8.         <![CDATA[
  9.             import flash.text.engine.FontWeight;
  10.             import flashx.textLayout.formats.TextLayoutFormat;
  11.  
  12.             private function btn_click(evt:MouseEvent):void {
  13.                 var styleObj:TextLayoutFormat = new TextLayoutFormat();
  14.                 styleObj.fontWeight = FontWeight.BOLD;
  15.                 styleObj.color = 0xFF0000; // red
  16.                 textArea.setFormatOfRange(styleObj);
  17.             }
  18.         ]]>
  19.     </fx:Script>
  20.  
  21.     <mx:ApplicationControlBar width="100%" cornerRadius="0">
  22.         <s:Button id="btn"
  23.                 label="Style selected text"
  24.                 click="btn_click(event);" />
  25.     </mx:ApplicationControlBar>
  26.  
  27.     <s:TextArea id="textArea"
  28.             horizontalCenter="0"
  29.             verticalCenter="0">
  30.         <s:content>
  31.             <s:p>Select some text and click the button to apply a bold/red style.</s:p>
  32.         </s:content>
  33.     </s:TextArea>
  34.  
  35. </s:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Gumbo, TextArea | No Comments » | Tags: ,

Search Posts