I agree. I can see both sides of the point--more granular encapsulation,
etc. However, in addition to creating more breadcrumbs to follow, it may not
be all that practical in every case. You may not always know you need this
and may have to deal with less manageable code more and more as the need
arises, as Steven said.
I think the example I used in the link I posted was a pre-existing listener
but the additional need to call it manually. I think I used a timer, set for
every 5 minutes for example, but the need to call it once right away. If you
ran into something similar more than a time or two, you'd end up with lots
of headless wrappers just to call the function two ways.
I prefer either sending null or setting up null as the default value. The
only minor problem with the latter is that it assumes you foresee a need to
do this. So, if you wanted to do it later in the game, you'd need to go back
and add in the null default.
I wouldn't recommend habitually adding null as a default for every listener
because then you lose a bit of error reporting convenience. That is, you
will still get TypeErrors if you send in the wrong type, but if you just
forget to send an event argument, without the need for the situation
originally described, you won't get the 'wrong number of parameters,
expected 1' error.
On 4/5/08 11:06 PM, "Steven Sacks" wrote:
> I disagree with this approach. It's unnecessary and makes code less
> manageable. It's cleaner to set the argument as optional (event = null)
> than write another subroutine.
>
>
> Matt S. wrote:
>> You might want to separate the functions, so you would have
>> myFunction(), which you could call from anywhere, and myClickHandler,
>> which would handle the mouse event specifically. So:
>>
>> fancyButton.addEventListener(MouseEvent.CLICK, myClickHandler);
>>
>> private function myClickHandler(e:MouseEvent):void {
>> myFunction();
>> }
>>
>> private function myFunction():void{
>> //blah blah...
>> }
Rich
http://www.LearningActionScript3.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders