博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助
隐藏
yexin218.cublog.cn
Flex中检测TextInput控件的双击事件
接下来的例子展示如何通过设置doubleClick 事件来检测Flex中TextInput控件的双击事件。
 隐藏代码

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/24/detecting-a-double-click-on-a-textinput-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function textInput_doubleClick(evt:MouseEvent):void {
                var ti:TextInput = evt.currentTarget as TextInput;
                ti.enabled = !ti.enabled;
                ti.editable = ti.enabled;
            }
        ]]>
    </mx:Script>

    <mx:TextInput id="textInput1"
            text="The quick brown fox jumped over the lazy dog"
            doubleClickEnabled="true"
            doubleClick="textInput_doubleClick(event);" />

    <mx:TextInput id="textInput2"
            text="The quick brown fox jumped over the lazy dog"
            doubleClickEnabled="true"
            doubleClick="textInput_doubleClick(event);" />

</mx:Application>

AS实现方式:

 

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/24/detecting-a-double-click-on-a-textinput-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();">

    <mx:Script>
        <![CDATA[
            import mx.controls.TextInput;

            private var textInput1:TextInput;
            private var textInput2:TextInput;

            private function init():void {
                textInput1 = new TextInput();
                textInput1.text = "The quick brown fox jumped over the lazy dog";
                textInput1.doubleClickEnabled = true;
                textInput1.addEventListener(MouseEvent.DOUBLE_CLICK,
                            textInput_doubleClick);
                addChild(textInput1);

                textInput2 = new TextInput();
                textInput2.text = "The quick brown fox jumped over the lazy dog";
                textInput2.doubleClickEnabled = true;
                textInput2.addEventListener(MouseEvent.DOUBLE_CLICK,
                            textInput_doubleClick);
                addChild(textInput2);
            }

            private function textInput_doubleClick(evt:MouseEvent):void {
                var ti:TextInput = evt.currentTarget as TextInput;
                ti.enabled = !ti.enabled;
                ti.editable = ti.enabled;
            }
        ]]>
    </mx:Script>

</mx:Application>

查看Demo演示

原创作者: peterd。翻译整理:一路风尘

 TAG Flex TextInput
发表于: 2008-06-30,修改于: 2008-06-30 21:56,已浏览190次,有评论0条 推荐 投诉

给我留言
版权所有 ChinaUnix.net 页面生成时间:2.51996