使用 ActionScript 添加 MXML 组件作为主应用程序的子组件
如何使用 ActionScript 添加 MXML 组件作为主应用程序的子组件。不可能实例化它,是吗?假设每个 mxml 文件后面都有一个 actionscrpt3 类,我尝试导入它,但 id 没有显示。
How can I add an MXML component as a child of the main application using ActionScript. It's not possible to instatiate it, is it? Assuming that behind every mxml file stands an actionscrpt3 class, I tried to import it but id didn't show up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要熟悉 Flex 组件生命周期: http://msimtiyaz.wordpress.com/flex/adobe-flex-component-instantiation-life-cycle/
它解释了mxml组件背后的actionscript代码,熟悉它很重要,因为如果你实现如果你的组件不正确,它真的会减慢你的应用程序的速度。
无论如何,我认为您可能对导入的作用感到困惑。导入语句使代码可以在您的代码中使用,但它不会创建组件。您需要像在动作脚本中创建任何对象一样创建一个组件,然后需要将该组件添加到显示列表中以使其显示。
执行此操作的适当位置是在 createChildren() 函数中:
You'll want to familiarize yourself with the flex component lifecycle: http://msimtiyaz.wordpress.com/flex/adobe-flex-component-instantiation-life-cycle/
It explains the actionscript code behind the mxml components, and it's important to be familiar with, because if you implement your components incorrectly, it can really slow down your application.
Anyway, I think you may be confused about what imports do. Import statements make the code available to use in your code, but it wouldn't create a component. You'd need to create a component the same way you create any object in actionscript, and then you'll need to add that component to the display list to make it show up.
The appropriate place to do this is in the createChildren() function: