tags:

views:

13

answers:

1

I have an httpservice object instantiated and have defined an event listener to handle the result.

e.g.

http.addEventListener(ResultEvent.RESULT,function (event:ResultEvent):void {
    // handle result
    // ...

//should I remove this anonymous event listener?:
event.currentTarget.removeEventListener(event.type, arguments.callee);

});

I'm only curious from an efficiency/best practice point of view.

A: 

Depends if you're going to reuse it, and/or if you need closure variables from the current scope. If there's no reuse, then data-hiding might suggest making it local or at least private. If it's something that's going to be reused, or something that might even be overridden by a subclass, then make it separate and protected.

My 2 cents.

Update:

Whoops, I thought the question was whether the listener should be anonymous or not.

You should definitely remove any listener, anonymous or not, if it's no longer needed. Otherwise, it's useless cpu usage if the event keeps firing.

eruciform