`

EventListener的add和remove

    博客分类:
  • Flex
阅读更多
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="Button_willTrigger_buttonDown_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            import mx.utils.StringUtil;

            private function verify_click():void {
                var listener:Boolean = btn.hasEventListener(FlexEvent.BUTTON_DOWN);
                var trigger:Boolean = btn.willTrigger(FlexEvent.BUTTON_DOWN);
                var str:String = "hasEventListener() = {0}{1}willTrigger() = {2}";
                Alert.show(StringUtil.substitute(str, listener, "n", trigger));
            }

            private function addEventListener_click():void {
                btn.addEventListener(FlexEvent.BUTTON_DOWN, btn_buttonDown);
                verify_click();
            }

            private function removeEventListener_click():void {
                btn.removeEventListener(FlexEvent.BUTTON_DOWN, btn_buttonDown);
                verify_click();
            }

            private function btn_buttonDown(evt:FlexEvent):void {
                Alert.show(evt.type);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Verify listeners"
                click="verify_click();" />

        <mx:Spacer width="100%" />

        <mx:Button label="addEventListener()"
                click="addEventListener_click();" />
        <mx:Button label="removeEventListener()"
                click="removeEventListener_click();" />
    </mx:ApplicationControlBar>

    <mx:Button id="btn" label="Button" />

</mx:Application>
 
分享到:
评论

相关推荐

    java事件监听方法和代码

    如键盘事件KeyEvent对应的接口是: public interface KeyListener extends EventListener { public void keyPressed(KeyEvent ev); public void keyReleased(KeyEvent ev); public void keyTyped(KeyEvent ev); } 这...

    eventQueue:这是基于javascript的事件队列文件!

    如何使用 Introduct the js file,then you can use add or remove to add or remove listener!演示结果在每个浏览器中都是 1,2,3! var a = document.getElementById('a');add(a,'click',function(){alert&#40;1&#41...

    react-socket-event:React套接字事件

    React的Socket事件 安装 yarn add react-socket-event ... //remove listener on unmount the component } , [ ] ) ; SocketEvent . emit ( 'my-event' , 'hello, world' ) ; SocketEvent . clear ( 'my-

    HXSDKHelper.java 环信Demo 

    protected EMEventListener eventListener = null; /** * contact list in cache */ private Map, User&gt; contactList; /** * robot list in cache */ private Map, RobotUser&gt; robotList; private ...

    聊天系统计算机相关论文

    //并将name和ip用":"分开,在服务器端将用一个 //StringTokenizer类来读取数据 String userinfo = nameTextField.getText() + Constants.SEPERATOR + InetAddress.getLocalHost()....

    jquery-clickout:使用jQuery处理clickout事件

    您可以通过on和off方法正常使用它: // Add a clickout listener$ ( 'button' ) . on ( 'clickout' , function ( e ) { console . log ( 'click outside button' )} )// Remove a clickout listener$ ( 'button' ) ...

    DotNetFtpSources

    this.RemoveSession(i); } //on d閏lenche l'関鑞ement Stopped if(this.Stopped!=null) { Stopped(this,EventArgs.Empty); } } } catch{} } /// /// ...

    JavaScript权威指南

    Advanced Event Handling with DOM Level 2 Section 19.3. The Internet Explorer Event Model Section 19.4. The Netscape 4 Event Model Chapter 20. Compatibility Techniques Section 20.1. Platform...

    ViewPager 放大缩小左右移动

    * Position of the last motion event. */ private float mLastMotionX; private float mLastMotionY; /** * ID of the active pointer. This is used to retain consistency during * drags/flings if ...

    swing文件拖拽

    // drag source listener } public void dragDropEnd(DragSourceDropEvent e) { ghostImage = null; sourceNode = null; } public void dragEnter(DragSourceDragEvent e) { } public void dragExit...

    C#全能速查宝典

    《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用...

    servlet2.4doc

    The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object. addCookie(Cookie) - Method in interface javax.servlet.http.HttpServletResponse Adds the ...

    Doctrine ORM for PHP.pdf

    Table of Contents Introduction....................................................................................................13 Code Examples.........................................................

Global site tag (gtag.js) - Google Analytics