为什么 mxml 不支持组件构造函数?
为什么 Flex 框架的 mxml 语言不支持组件的构造函数或接受组件的构造函数参数?据我所知,如果 ActionScript 对象采用构造函数参数,则不可能在 mxml 中声明它。我很好奇原因。它是 Adobe 的设计选择还是与声明性语言的工作方式有关?例如,为什么不允许:
<myNameSpace:MyComponent constructor="{argArray}"/>
Why doesn't the Flex framework's mxml language support a constructor for components or accept constructor arguments for components? It's as far as I know not possible to declare an ActionScript object in mxml if it takes constructor arguments. I'm curious about the reason. Is it a design choice by Adobe or related to how declarative languages work? For example, why not allow:
<myNameSpace:MyComponent constructor="{argArray}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以阅读 IMXMLObject 帮助 API,了解有关您的问题的更多信息。他们没有确切说明为什么 mxml 不支持构造函数,但它表示您必须通过其生命周期事件来控制您的 mxml 组件:预初始化、初始化和创建完成。
我认为这是一个设计决策,考虑到 mxml 会直接转换为 AS3 代码(您可以编译应用程序并添加 keep-generate-actionscript=true 并查看它会生成什么)。
You can read IMXMLObject help API for more information about your question. They're not telling exactly why an mxml doesn't support constructors, but it says that you must control your mxml component throught its lifecycle events: preinitialize, initialize and creationComplete.
I suppose that's a design decision, considering that an mxml gets translated directly to AS3 code (you can compile your application adding keep-generated-actionscript=true and see what it produces).
即使在 MXML 中定义了一个类,也可以通过实例化实例变量来实现构造函数,如下所示。这将在调度“preinitialize”或“creationComplete”等各种事件之前被调用。
此外,类变量可以用类似的方式初始化,如下所示。
Even if a class is defined in MXML, it is possible to implement a constructor via instantiating an instance variable as follows. This will get called before various events like "preinitialize" or "creationComplete" are dispatched.
Moreover, class variables can be initialized in a similar way as follows.