解决方案:
如果你有同样的问题,addElement()而不是 addChild() 是什么
我正在尝试从 mxml 转移到 actionsctipt。我有一个<s:Rect>
我已经创建并设置了它的属性,但是在添加它时遇到了麻烦。
var aRect:Rect = new Rect();
//set properties like aRect.x, aRect.y, aRect.width, aRect.height
//tried adding it various ways
addChild(aRect);
Application.addChild(aRect);
Application.application.addChild(aRect);
stage.addChild(aRect);
但我不断收到错误 1067:将 spark.primitives:Rect 类型的值隐式强制转换为不相关的类型 flash.display:DisplayObject
最初在 mxml 中,它就在里面,<s:Application>
没有嵌套在任何东西里面
<s:Application>
<s:Rect id="aRect" x="10" y="10" width="15%" height="15%">
//then fill code here, removed for readability
</s:Rect>
</s:Application>
有什么关系,我认为actionscript会比mxml更好。