[ 
https://issues.apache.org/jira/browse/FLEX-33608?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13715067#comment-13715067
 ] 

Mark Kessler commented on FLEX-33608:
-------------------------------------

I've listed a work around below add it to any class you wish that utilizes the 
EventDispatcher(pretty much every class).  It overrides a few methods to 
duplicate the functionality of the original EventDispatcher while adding in the 
new methods.  

The original EventDispatcher is part of flash.events (something Adobe has 
control over not Apache Flex).  We may have a partial solution in the future, 
but cannot get at the root of it without a successful ticket with Adobe.


    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    /**
    *  @private
    */
    protected var alEventListenerList:ArrayList = new ArrayList();


    /**
    *  Gets the arraylist that
    */
    public function get eventListenerList():ArrayList
    {
        return alEventListenerList;
    }


    //--------------------------------------------------------------------------
    //
    //  Overridden methods
    //
    //--------------------------------------------------------------------------

    /**
    *  Override addEventListener to store the entries in an event array list.
    */
    override public function addEventListener(type:String, listener:Function, 
useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = 
false):void
    {
        alEventListenerList.addItem({typeValue:type, listenerValue:listener, 
useCaptureValue:useCapture});

        super.addEventListener(type, listener, useCapture, priority, 
useWeakReference);
    }


    /**
    *  Override the removeEventListener to remove the entries in an event array 
list.
    */
    override public function removeEventListener(type:String, 
listener:Function, useCapture:Boolean = false):void
    {
        var oTemp:Object;
        var nListenerTotal:uint = alEventListenerList.length;
        var nLoopingIndex:uint = 0;


        super.removeEventListener(type, listener, useCapture);


        for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
        {
            oTemp = alEventListenerList.getItemAt(nLoopingIndex);

            if (oTemp.typeValue == type && oTemp.listenerValue == listener && 
oTemp.useCaptureValue == useCapture)
            {
                alEventListenerList.removeItemAt(nLoopingIndex);
                return;
            }
        }

    }


    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    /**
    *  Removes all event listeners.
    */
    public function removeAllEventListeners():void
    {
        var oTemp:Object;
        var nListenerTotal:uint = alEventListenerList.length;
        var nLoopingIndex:uint = 0;


        for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
        {
            oTemp = alEventListenerList.getItemAt(nLoopingIndex);

            super.removeEventListener(oTemp.typeValue, oTemp.listenerValue, 
oTemp.useCaptureValue);
        }

        alEventListenerList.removeAll();
    }


    /**
    *  Removes all event listeners of the specified type.
    */
    public function removeEventListenersByType(type:String):void
    {
        var oTemp:Object;
        var nListenerTotal:uint = alEventListenerList.length;
        var nLoopingIndex:uint = 0;


        for (nLoopingIndex = 0; nLoopingIndex < nListenerTotal; nLoopingIndex++)
        {
            oTemp = alEventListenerList.getItemAt(nLoopingIndex);

            if (oTemp.typeValue == type)
            {
                super.removeEventListener(oTemp.typeValue, oTemp.listenerValue, 
oTemp.useCaptureValue);

                alEventListenerList.removeItemAt(nLoopingIndex);
                nListenerTotal -= 1;
                nLoopingIndex -= 1;
            }
        }

    }

                
> Add function "removeAllEventListener()"
> ---------------------------------------
>
>                 Key: FLEX-33608
>                 URL: https://issues.apache.org/jira/browse/FLEX-33608
>             Project: Apache Flex
>          Issue Type: New Feature
>          Components: Spark Components
>    Affects Versions: Apache Flex 4.9.0
>            Reporter: Robbyn Gerhardt
>            Assignee: Mark Kessler
>              Labels: event, removeEventListener
>             Fix For: Apache Flex 4.10.0
>
>   Original Estimate: 12h
>  Remaining Estimate: 12h
>
> Can you add a function that removes all events of a component?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to