Flex 声明订单错误
在 Flex 中,您可以对非 UI 元素使用声明标签。
问题: 声明中类的顺序按升序或其他方式排序...
这意味着在本例中,AClass 将在 BClass 之前实例化:
<fx:Declarations>
<local:AClass />
<local:BClass />
</fx:Declarations>
但在下一个示例中,AClass 仍将在 BClass 之前实例化,即使 BClass 是第一个。这是意外的行为,因为 AClass 可能依赖于 BClass,但会首先实例化,即使它按声明顺序出现在后面。
<fx:Declarations>
<local:BClass />
<local:AClass />
</fx:Declarations>
A类
public class AClass
{
public function AClass()
{
var _instance:Object = BClass.instance;
trace("AClass " + _instance);
}
}
和B类
public class BClass
{
private static var _instance:Object;
public function BClass()
{
_instance = new Object();
trace("BClass " + _instance);
}
public static function get instance():Object{
return _instance;
}
}
我疯了吗?
In Flex you can use Declarations tags fo non UI elements.
Problem:
The order of classes inside the Declaration is sorted ascending or something...
Meaning that in this example, AClass will be instantiated before BClass:
<fx:Declarations>
<local:AClass />
<local:BClass />
</fx:Declarations>
But in the next example, AClass will STILL be instantiated before BClass even though BClass is first. This is unexpected behavior because AClass may depend on BClass but will instantiate first even though it comes afterwards in the declaration order.
<fx:Declarations>
<local:BClass />
<local:AClass />
</fx:Declarations>
AClass
public class AClass
{
public function AClass()
{
var _instance:Object = BClass.instance;
trace("AClass " + _instance);
}
}
And BClass
public class BClass
{
private static var _instance:Object;
public function BClass()
{
_instance = new Object();
trace("BClass " + _instance);
}
public static function get instance():Object{
return _instance;
}
}
Am I crazy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚通过检查生成的动作脚本(使用 -keep 标志作为额外的编译器参数)进行了快速测试,并且声明的顺序似乎被正确保留。
您确定在更改对象的顺序后进行了干净的编译吗?
I just did a quick test by inspecting the generated actionscript (use the -keep flag as an extra compiler argument) and the order of declaration seems to be preserved correctly.
Are you sure you did a clean compile after changing the order of the objects?