Voxl
Voxl

Reputation: 111

Flash function overloading in Haxe

I am having some trouble figuring out how to overload a function in Flash using Haxe. I know that Flash does not allow overloads but can accept function parameters without a type declared, but I am unsure as how to replicate this trick in Haxe.

EDIT: Since this does not appear to be possible, are there any known tricks that can be used to get around this limitation?

Upvotes: 3

Views: 1606

Answers (3)

heavilyinvolved
heavilyinvolved

Reputation: 1575

The Haxe website has an example of how to achieve this here: http://old.haxe.org/ref/optional_args

I don't think haxe supports true method overloading... not sure though. Good luck!

Upvotes: 4

aerique
aerique

Reputation: 981

There was recently a discussion about this on the Haxe mailinglist: http://lists.motion-twin.com/pipermail/haxe/2010-May/035650.html

The most pertinent post is by Haxe's author: http://lists.motion-twin.com/pipermail/haxe/2010-May/035659.html

The tl;dr version is because Flash 9 doesn't support it they removed the ability to do it for all platforms.

Upvotes: 1

moveaway00
moveaway00

Reputation: 917

You can use a trick similar to what is done in AS3, if I'm reading your question correctly. If you declare the function to take parameters that are Dynamic, you can then do different things based upon the runtime type of the parameters passed. e.g.

public function bar(param1:Dynamic, param2:Dynamic):Dynamic
{
  if(Std.is(param1, Float) && Std.is(param2, Float))
    doStuffWithFloats(param1, param2);
  else if(Std.is(param1, String) && Std.is(param2, String))
    doStuffWithStrings(param1, param2);
}

Upvotes: 0

Related Questions