博客原址:http://tongqiuyan.blog.163.com/blog/static/19554530220119162275231/

下面的flash是有Flex创建的文本编辑器运行效果:

 

源码如下:

 
  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" fontSize="12">  
  3.     <mx:Script>  
  4.         <![CDATA[  
  5.             // 导入类库  
  6.             import mx.controls.TextInput;  
  7.             import mx.controls.TextArea;  
  8.             import mx.events.FlexEvent;  
  9.             // 定义最大输入字数  
  10.             private const MAX_CHARS:uint = 100;  
  11.             // 设置文本输入区域的最大输入字数  
  12.             private function richTextEditor_creationComplete(evt:FlexEvent):void  
  13.             {  
  14.                 RichTextEditor(evt.currentTarget).textArea.maxChars = MAX_CHARS;  
  15.             }  
  16.             // 显示当前输入字数和最大字数  
  17.             private function richTextEditor_change(evt:Event):void  
  18.             {  
  19.                 var rte:RichTextEditor = evt.currentTarget as RichTextEditor;  
  20.                 var rteTA:TextArea = rte.textArea as TextArea;  
  21.                 rte.status = rteTA.length + "/"+rteTA.maxChars;  
  22.             }  
  23.             // 设置工具栏内超链接输入框的显示或者隐藏  
  24.             private function toogle_linkTextInput():void  
  25.             {  
  26.                 var textInput:TextInput = richTextEditor.linkTextInput;  
  27.                 var isSelected:Boolean = cbLinkButton.selected;  
  28.                 textInput.visible = isSelected;  
  29.                 textInput.includeInLayout = isSelected;  
  30.             }  
  31.         ]]>  
  32.     </mx:Script>  
  33.     <mx:Array id="fontFamilyArr">  
  34.         <mx:String>Arial</mx:String>  
  35.         <mx:String>Verdana</mx:String>  
  36.         <mx:String>黑体</mx:String>  
  37.         <mx:String>楷体</mx:String>  
  38.     </mx:Array>  
  39.     <mx:Panel width="650" height="400" layout="horizontal" title="文本编辑器">  
  40.         <mx:VBox height="100%" width="100%">  
  41.             <mx:ApplicationControlBar dock="true" width="100%">  
  42.                 <mx:CheckBox id="cbBar" label="显示工具栏:" selected="true" />  
  43.                 <mx:CheckBox id="cbLinkButton" label="显示超链接按钮:" selected="true" change="toogle_linkTextInput();" />  
  44.             </mx:ApplicationControlBar>  
  45.             <mx:RichTextEditor id="richTextEditor" width="100%" height="100%" title="请输入任意文字,并修改格式。" showToolTips="true" 
  46.                                fontFamilyToolTip="字体" colorPickerToolTip="颜色" showControlBar="{cbBar.selected}" 
  47.                                change="richTextEditor_change(event);" creationComplete="richTextEditor_creationComplete(event);" 
  48.                                fontFamilyArray="{fontFamilyArr}">  
  49.             </mx:RichTextEditor>  
  50.         </mx:VBox>  
  51.     </mx:Panel>  
  52. </mx:Application>  

涉及到控件主要是RichTextEditor、VBox、Panel等。