宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > AS2与AS3技术

[AS3]as3侦听用户输入文本源代码示例

2016-10-13 00:16:48 点击量:13 标签: 收藏本文

通过TextEvent事件监听用户对文本框内容的修改,如删除,剪切,插入或者拷贝等操作,对文本框的每一次修改都会激活textInput事件,可以通过event.preventDefault()取消显示输入的文本

  1. package { 
  2.  import flash.display.Sprite; 
  3.  import flash.events.TextEvent; 
  4.  import flash.text.TextField; 
  5.  import flash.text.TextFieldType; 
  6.  public class Sample0414 extends Sprite 
  7.  { 
  8.   private var lblInfo:TextField; 
  9.    
  10.   public function Sample0414() 
  11.   { 
  12.    var textBox:TextField = new TextField(); 
  13.    textBox.type = TextFieldType.INPUT; 
  14.    textBox.background = true
  15.    textBox.width = 200
  16.    textBox.height = 20
  17.    textBox.addEventListener(TextEvent.TEXT_INPUT,onTextInput); 
  18.    this.addChild(textBox); 
  19.   } 
  20.    
  21.   private function onTextInput(event:TextEvent):void 
  22.   { 
  23.    if(event.text.toLowerCase().indexOf("<script>")>-1) 
  24.    { 
  25.     event.preventDefault(); 
  26.    } 
  27.   } 
  28.  } 

 

ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室