开发者

Flex library projects: `undefined` is "unknown or not a compile-time constant"?

I'm in the process of refactoring a Flex application into a "library project", and one of the, err, interesting errors I've come across involves a function like this:

function spam(eggs:*=undefined):void {
    ...
}

While it was a "Flex application", this function compiled without issue… But when I try to build it as a "library pro开发者_StackOverflow社区ject", the compiler gives me the error:

1047: Parameter initializer unknown or is not a compile-time constant.

So, uuhh… Why? And is there anything I can do to fix that?


There's a bug in jira (link) that says mxmlc and the flash compiler behave differently when working with parameter initializers. As the library projects are compiled using a different compiler (compc in place of mxmlc) I suspect it might be the same issue.

You can probably change the function to something like this, if you need it to be undefined:

function spam(eggs:*=null):void {
   if (eggs is null) eggs = undefined;
}


Is the class with this code being used at all? A Flex Project may have optimized it out of the project if it's never used; thus not throwing an error. A library project would not do that.


I would recommend using null as the default value instead of undefined. Isn't there a bit of a paradox to initialize a value as 'undefined' ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜