2 Replies Latest reply on Apr 19, 2010 4:52 PM by GordonSmith

    Declaring listener in mxml.

    SpaghettiCoder Level 3

      Is this correct? if you declare a listener in mxml on a button




      you can't remove the click listener from that button in actionscript?


      on the other hand if you declare a function to an object in actionscript, you can remove the listener from that object in actionscript???

        • 1. Re: Declaring listener in mxml.
          David_F57 Level 5





          in AS mybtn.removeEventListener(MouseEvent.CLICK,myfunction);


          basically mxml just wraps itself around AS/API calls much the same way it does for properties , so mxml allows you to assign values rather than having to use the full call.


          With say obj.resort = functionX() you remove that function by obj.resort=null;



          • 2. Re: Declaring listener in mxml.
            GordonSmith Level 4

            When you write code like


                <s:Button id="b1" click="doSomething()"/>


            the compiler autogenerates an event handler like


                private function _b1_clickHandler(event:MouseEvent):void





            and registers it with a call like


                b1.addEventListener("click", _b1_clickHandler);


            You can call removeEventListener(...) to unregister it, but to do so you have to know the name the compiler chose for the autogenerated method. You shouldn't write code like this because the naming algorithm might change in a future version of the compiler.


            MORAL: If you want to remove an event handler, write the handler yourself in ActionScript and register it yourself with addEventListener().


            Gordon Smith

            Adobe Flex SDK Team