成功,附源码 flex cursor textarea 光标 位置 插入 insert caret

			private function onConsumeSmsParamClicked(e:MouseEvent):void{
				this.consumeSmsTemplate.str = e.target.text;
				this.consumeSmsTemplate.focusManager.setFocus(this.consumeSmsTemplate);
				
			}

 

	<mx:HBox verticalAlign="bottom">
		<trade:TextAreaExt id ="prepaySmsTemplate"   styleName="input01" width="400" height="80" backgroundColor="#ffffff"/>
		<mx:Button label="预览内容" id="prepaySmsPreview" height="20" fontSize="12" fontWeight="normal"/>
	</mx:HBox>
			
	       <mx:HBox horizontalGap="0" id="prepaySmsParam" fontSize="12" fontWeight="normal">
        <mx:Label text="动态参数:"/>
        <mx:VBox verticalGap="0">
               <mx:HBox horizontalGap="3">
            <mx:Text text="会员姓名" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu11" mouseOver="canshu11.setStyle('textDecoration',null);" mouseOut="canshu11.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
            <mx:Text text="卡号后四位" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu12" mouseOver="canshu12.setStyle('textDecoration',null);" mouseOut="canshu12.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
            <mx:Text text="充值时间" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu13" mouseOver="canshu13.setStyle('textDecoration',null);" mouseOut="canshu13.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
            <mx:Text text="充值金额" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu15" mouseOver="canshu15.setStyle('textDecoration',null);" mouseOut="canshu15.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
           </mx:HBox>
            <mx:HBox horizontalGap="3">
            <mx:Text text="预存余额" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu16" mouseOver="canshu16.setStyle('textDecoration',null);" mouseOut="canshu16.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
             <mx:Text text="积分剩余数量" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu18" mouseOver="canshu18.setStyle('textDecoration',null);" mouseOut="canshu18.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
             <mx:Text text="优惠券剩余数量" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu19" mouseOver="canshu19.setStyle('textDecoration',null);" mouseOut="canshu19.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
             <mx:Text text="商户简称" styleName="lan" textDecoration="underline" fontWeight="normal" id="canshu20" mouseOver="canshu20.setStyle('textDecoration',null);" mouseOut="canshu20.setStyle('textDecoration','underline');" buttonMode="true" useHandCursor="true" mouseChildren="false"/>
            </mx:HBox>
            </mx:VBox>
        </mx:HBox>
 this.prepaySmsParam.addEventListener(MouseEvent.CLICK,onPrepaySmsParamClicked);
    
  

  

package com.tongcard.tcc.main.view.deskBack.sysManage.config.trade
{
	import flash.events.Event;
	import flash.events.FocusEvent;
	
	import mx.controls.TextArea;

	public class TextAreaExt extends TextArea 
	{
	 	public var insertText:String = '';
		public function TextAreaExt()
		{
			super(); 
			this.addEventListener(FocusEvent.FOCUS_IN,onFocusIn);
		}

		private function onFocusIn(e:Event):void{
			trace(this.textField.caretIndex);
		 	this.textField.replaceText(this.textField.caretIndex,this.textField.caretIndex,insertText);
			this.insertText = '';
		}

	}
}

 

 

 

 

 

 

 

 

var insertIndex:int = tf.getCharIndexAtPoint( tf.mouseX, tf.mouseY );
tf.replaceText( insertIndex, insertIndex, "Here is some more text" );
啊哈,

http://www.flexdeveloper.eu/forums/flex-builder-flash-builder-eclipse/how-to-get-the-cursor-position-in-the-textarea/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值