views:

56

answers:

2

when extending a class, is it impossible to override a method without also matching the parameters?

for example, i'd like to use the method's name, in this case it's a socket extension and the method i want to override is connect. however, i want to request additional parameters that the stock connect function does not request.

is the only alternative to create my own connect-like method with my own parameters, call super.connect from this function and override the stock connect function to throw an error if it's called?

that all kind of sounds like a train wreck.

+3  A: 

Function overloading is not supported in ActionScript (however Darron Schall demonstrated some kind of pseudo overloading in this article).

I think in your case it's only left over to create your own connectEx method.

splash
by "overloading" do you mean overriding a method with additional parameters?
TheDarkInI1978
@TDI1978: Right. I mean function overloading.
splash
A: 

Sadly, overloading is not supported. As a next best option, you could consider optional arguments. This would allow you to pass as few or as many params as you want to a method. The method would receive these params in an array and you could handle them however you want from that point on.

Here's how a method using optional params would look:

function someMethod(...params):void
{
    for(var i:int = 0 ; i < params.length ; i++ )
    {
        trace("parameter: " + params[i]);
    }
}

You can read more about optional parameters here.

TheoryNine