Flex编译器,不是编译时常量,但仅在实例方法中
我在使用 Flex 编译器(使用 Flash Builder 4.5)时遇到了一个非常奇怪的问题,这是我以前从未遇到过的。
我试图创建一个类的实例(存在于同一个包中),编译器不会将该类识别为编译时常量,而只能在实例方法中识别。类方法(静态)将毫无问题地编译。
这个类在任何地方都可以使用,没有任何问题。就在这一处,它不会在实例方法中编译。毫无意义。
我已经尝试了我能想到的一切...
- 添加了 UploadDate 的导入(即使该类位于同一个包中)
- 清理构建了项目(以及所有父/子项目)
- 删除了代码模型缓存(.metadata/.plugins/ com.adobe.flexbuilder.codemodel/*)
- 删除了所有生成的资源缓存 (.../com.adobe.flexide.editorcore/GenerateAssets/*)
- 使用不同的 flex sdk 编译(3.2, 3.5, 3.6)
这是代码:
package classes
{
import classes.UploadDate;
[Bindable]
public class UserImages {
....
//this compiles with no errors
public static function classMethod():void {
var ud:UploadDate = new UploadDate();
}
//this will not compile
public function instanceMethod():void {
//1046: Type was not found or was not a compile-time constant: UploadDate
var obj:UploadDate = new UploadDate();
}
//this is the ugly workaround I am currently using (works fine at Runtime)
public function hackyMethod():void {
var Def:Class = getDefinitionByName("classes.UploadDate") as Class;
var obj:* = new Def();
}
}
}
和 UploadDate 类:
package classes
{
[Bindable]
public class UploadDate {
public var date:String;
public var numImages:int;
public UploadDate() {
}
}
}
有人以前见过这个吗?
谢谢, 马特
I am having a very strange issue with the flex compiler (using Flash Builder 4.5) that I have never come across before.
I am trying to create an instance of a class (that exists in the same package) and the compiler will not recognize the class as a compile-time constant, but only in instance methods. Class methods (static) will compile without issue.
This class is being used all over the place without issue. Just in this one place it will not compile in instance methods. Makes no sense.
I have tried everything I can think of...
- Added an import for UploadDate (even though the class is in the same package)
- Clean built the project (and all parent/sub projects)
- Deleted code model cache (.metadata/.plugins/com.adobe.flexbuilder.codemodel/*)
- Deleted all generated assets cache (.../com.adobe.flexide.editorcore/GeneratedAssets/*)
- Compiled with different flex sdk's (3.2, 3.5, 3.6)
Here is the code:
package classes
{
import classes.UploadDate;
[Bindable]
public class UserImages {
....
//this compiles with no errors
public static function classMethod():void {
var ud:UploadDate = new UploadDate();
}
//this will not compile
public function instanceMethod():void {
//1046: Type was not found or was not a compile-time constant: UploadDate
var obj:UploadDate = new UploadDate();
}
//this is the ugly workaround I am currently using (works fine at Runtime)
public function hackyMethod():void {
var Def:Class = getDefinitionByName("classes.UploadDate") as Class;
var obj:* = new Def();
}
}
}
And the UploadDate class:
package classes
{
[Bindable]
public class UploadDate {
public var date:String;
public var numImages:int;
public UploadDate() {
}
}
}
Has anyone seen this before?
Thanks,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“在方法签名或实例属性中使用静态常量时,我遇到了类似的问题。这里的解决方案是重命名包含常量的类,以便它按字母顺序排列在所有其他类之前。尝试将 UploadDate 重命名为 AUploadDate。” – Jens Struwe 2011-08-18 7:12
"I encountered a problem like that when using static constants in method signatures or instance properties. The solution here was to rename the class which contains the constants so that it was alphabetically ordered before all other classes. Try to rename UploadDate to AUploadDate." – Jens Struwe Aug 18 '11 at 7:12