FLEX文本编辑的关键词 : htmlText
FLEX的文本显示控件如 Text、TextArea、RichTextEditor等都有htmlText属性。
进行编辑时是符合html规范的
加粗用<b></b>下划线<u></u>样式用<font>等等
这是一个外部超链接的例子
txt.htmlText= "<a href='http://www.asarea.cn' target='_blank'><u><font color='#2969c0' size='13'>请点击</font></u</a>";
但是如何实现点击链接调用flash内部的方法?as如何感知按钮被点击?那就要用到文本显示空间的监控属性TextEvent.LINK,对Text、TextArea、RichTextEditor的监控都会有此属性
txt.addEventListener(TextEvent.LINK, linkHandler);
function linkHandler(event:TextEvent):void
{
···········································
}
这里的linkHandler在link被点击时触发,并通过event:TextEvent传递参数。
下面看一下TextEvent,先说一下触发机制,href的写法必须为<a href=/"event:参数/">的形式,显然,上面的例子并不能触发linkHandler。
第二点,TextEvent的主要参数,type,一般链接的type为“link”,text属性就是/"event:参数/"中的参数,这样就可以通过扩展linkHandler实现特定的链接执行特定的内部方法,例子如下
<textarea cols="50" rows="15" name="code" class="c-sharp"><?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" showCloseButton="{!isRegister}" height="550" close="PopUpManager.removePopUp(this)" xmlns:ng="dps.component.common.*" layout="absolute" creationComplete="init()" styleName="bluepanel" width="490" title="Welcome to Dynamic Printer System" verticalAlign="middle"> <!--<mx:Script source="../../../DPSImage.as"/>--> <mx:Script> <!--[CDATA[ import mx.managers.PopUpManager; import mx.core.Application; public var loginUserId:String; [Bindable]public var str:String; [Bindable]public var isRegister:Boolean; public function init():void { str = "<b>What is Dynamic Printer System</b> /n /n" + "Dynamic Printer System is a simple to use tool, created to help you monitoring printers across floors in different buildings even different sites. You will receive instance mail notification about the problem printers and fix it instantly. Further more, it provides reports for toner usage predication, response time report and printer paper jam frequency summary./n/n" + "<b>Tool highlights</b> /n/n" + "<b>Real Time Monitoring</b>, you will review the real time printer status/n" + "<b>Alert Notification</b>, system reminder you instantly for printer alerts /n" + "<b>E-Office Mapping</b>, you will find printer's physical location in our E-Office mapping /n" + "<b>Reporting</b>, you can analysis the toner usage, response time and paper jam frequency. /n/n" + "<b>Need more help?</b>/n/n" + "To find user support for Dynamic Printer System, please <a href="mailto:[email protected]" mce_href="mailto:[email protected]"><u><font color='#2754d5'>contact us</font></u></a>./n/n" + "========================================================/n" + "Link : <a href="/" mce_href="/""event:register/"><u><font color='#2754d5'>Request to use it!</font></u></a> Click here to register to use it."; txt.addEventListener(TextEvent.LINK, linkHandler); } private function linkHandler(event:TextEvent):void { if(event.text == "register") { register(); } if(event.text == "contract") { //register(); } } public function register():void { var addTenant:TenantAddView = TenantAddView(PopUpManager.createPopUp(Application.application as DisplayObject,TenantAddView,true)); addTenant.register = true; addTenant.isNew = true; addTenant.loginUserId = loginUserId; PopUpManager.centerPopUp(addTenant); } ]]--> </mx:Script> <mx:Metadata> [Event(name="UPDATE",type="flash.events.DynamicEvent",bubbles="true",cancelable="true")] </mx:Metadata> <mx:VBox paddingLeft="10" paddingRight="10" paddingTop="20" > <mx:Text htmlText="{str}" width="460" id="txt"/> </mx:VBox> </mx:TitleWindow> </textarea>
第一个链接实现了发送邮件到我的邮箱,第二个实现了调用内部的register()方法。