我以前从未遇到过的 flex 编译器(使用 Flash Builder 4.5)有一个非常奇怪的问题。
我正在尝试创建一个类的实例(存在于同一个包中),编译器不会将该类识别为编译时常量,而只会在实例方法中识别。类方法(静态)将毫无问题地编译。
这个类在所有地方都在使用,没有问题。就在这个地方,它不会在实例方法中编译。没有意义。
我已经尝试了我能想到的一切......
- 添加了 UploadDate 的导入(即使该类在同一个包中)
- 清理构建项目(以及所有父/子项目)
- 已删除代码模型缓存 (.metadata/.plugins/com.adobe.flexbuilder.codemodel/*)
- 删除了所有生成的资产缓存 (.../com.adobe.flexide.editorcore/GeneratedAssets/*)
- 使用不同的 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() {
}
}
}
有没有人见过这个?
谢谢,马特