我可以在 MXML 的一个文件中包含多个类吗?
我有一个仅在 A 类内部使用的 B 类。然而,classA 是用mxml 编写的,而不是actionscript 代码。是否可以在 MXML 中嵌套类或在同一 .mxml 文件中的根标记后添加另一个类? 澄清:我希望在同一个文件中用 MXML 编写这两个类,但我在 Adobe 文档中找不到指定具体方式的任何内容。
I have a classB that will only be used inside classA. However, classA is written as mxml, not actionscript code. Is it possible to nest classes in MXML or add another class after the root tag in the same .mxml file?
Clarification: I want both classes written in MXML within the same file, but I couldn't find anything in the Adobe documentation that specified how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,您不能在一个 MXML 文件中定义两个类,但您可以为这两个类使用相同的包(命名空间)并将 classB 设置为
internal
,因此它仅对该包内的类可见。No, you can't define two classes in one MXML file, but you can have the same package (namespace) for both classes and make classB
internal
, so its only visible for classes within that package.我相信您正在寻找 fx:Component 标签允许您在现有 MXML 文档中定义新的 MXML 文档:
I believe you are looking for the fx:Component tag that allows you to define a new MXML document within an existing MXML document:
如果嵌套类中需要多级继承,则 (在前面的答案中提到)的替代方法是使用 > 例如:
If multiple levels of inheritance are required in the nested classes, and alternative to <fx:Component> (mentioned in a previous answer) is to use <fx:Library> for example:
The <fx:Library> must be at the top of the MXML file. This syntax allows for several nested class definitions in a row, and each can extend the previous via inheritance.