开发者

Flex: Do I need to remove event handlers on an AsyncResponder? If so, how?

开发者 https://www.devze.com 2023-03-24 02:56 出处:网络
Do I need to remove event listeners on AsyncResponder events? i.e. public function DeleteItem():void { var asyncResponse:AsyncResponder = new AsyncResponder(DeleteItem_Result, DeleteItem_Fail);

Do I need to remove event listeners on AsyncResponder events?

i.e.

    public function DeleteItem():void
    {
        var asyncResponse:AsyncResponder = new AsyncResponder(DeleteItem_Result, DeleteItem_Fail);
        _myService.DeleteWorkout("test", asyncResponse);
    }

    private fun开发者_StackOverflowction DeleteItem_Result(event:Event):void
    {
        //If I do need to remove them, how do i remove the async responder event listeners?
    }

If I do need to remove them, how do I do it?


Do I need to remove event listeners on AsyncResponder events?

No, you do not. If you are creating the AsyncResponder and using ot over and over again, then by all means leave the listeners in there.

However, in some cases, if you won't be reusing the component over and over; I would recommend you do remove the event listeners, as that will remove a dependency pointing at the asyncResponder which may allow it to be released for garbage collection as appropriate.

In the Adobe Flex Framework it is pretty common to add and remove listeners "as needed." We use the approach in the Flextras Calendar, for example, when dealing with effects. Before starting the effect we add some event listeners for 'effect end'. Those listeners are removed in that effect end method.


Update:

To remove an event listener you would use code similar to this:

asyncResponder.removeEventListener('result' ,UpdatePics_result);
asyncResponder.removeEventListener('fault' ,UpdatePics_fault);
0

精彩评论

暂无评论...
验证码 换一张
取 消