[haXe] default parameters question

Yariv Sadan yarivvv at gmail.com
Fri Apr 14 18:22:18 CEST 2006


On 4/14/06, Nicolas Cannasse <ncannasse at motion-twin.com> wrote:
> >>>Hi list,
> >> >>>I have a couple of questions about the code below:
> >>>
> >>>1. Given that haxe doesn't accept default parameters to functions, how
> >>>come the call to myClip.lineStyle(1) works? Is this a bug?
> >>
> >>This is a special case for flash.* API : all parameters are optional.
> >
> >
> > Do you think it would be reasonable to propagate this behaviour to all
> > classes extending flash.* classes?
>
> It looks right to me.
>
> Since the special case treat for example all flash.MovieClip methods as
> having variable of arguments, you surely would not like to have a fixed
> number of arguments when you extends MovieClip.
>
> The current behavior is quite a hack. It's specific to Flash since the
> API are designed with a lot of optional arguments, making some of them
> painful to use with haXe as long as it doesn't have optional arguments
> declaration (and even in that case, there is still a lot of inheritent
> Dynamicity in the API).
>
> If you're interested in API design and compile-time error-checking, I
> would recommend you to write some API wrappers and only use theses
> wrappers instead of Flash API. That would ensure you a more strict API.
>
> BTW if you're interested I just added the -D check_flash_args that
> disable this behavior.
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

Thanks Nicolas.

I guess what I'll do is make a class (MyMovieClip) that extends
MovieClip and provides shorter versions for some of the built-in
functions, and then use extend MyMovieClip instead of MovieClip.

This solution is a bit clumsy, admittedly. When (if?) the haxe
compiler will allow default arguments, this problem will be easy to
solve by setting the default arguments for  functions in flash.* to
null.

Yariv



More information about the Haxe mailing list