3

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?

1
  • What exactly are you trying to accomplish? You mention method overloading and type inference but it's unclear what you are trying to do. Providing some pseudo code would be helpful... May 11, 2010 at 20:11

3 Answers 3

4

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!

1

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.

1
  • Those posts are not exactly related to what the questions is about. Those posts talk about methods in a subclassing overriding the superclass methods with a different method signature.
    – davr
    May 11, 2010 at 1:28
0

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.