开发者

Flash function overloading in Haxe

开发者 https://www.devze.com 2022-12-29 13:30 出处:网络
I am having some trouble figurin开发者_如何学Cg 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 declare

I am having some trouble figurin开发者_如何学Cg 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?


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!


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号