Flex:DisplayObject 单例
我想在整个应用程序的几个不同位置显示 Flex 组件。 它应该是组件的同一实例,而不是副本。 所以我考虑将组件制作为单例。
但问题是:
当我做这样的事情时: var vb1: VBox = new VBox(); var vb2: VBox = new VBox();
var comp : MyComponent = new MyComponent.getInstance();
vb1.addChild(comp);
vb2.addChild(comp);
该组件仅在“vb2”中显示。 我想当我们调用 vb2.addChild(comp) 时, 它删除了 vb1 中的子项。
有谁知道如何解决这个问题?
I want to display an Flex component in several different places through out the application. And it should be the same instance of the component, but not the copies.
So I think of making the Component as an Singleton.
But the problem is :
when I do something like this :
var vb1: VBox = new VBox();
var vb2: VBox = new VBox();
var comp : MyComponent = new MyComponent.getInstance();
vb1.addChild(comp);
vb2.addChild(comp);
The component is displayed only in "vb2" . I think when we call vb2.addChild(comp),
it removes the child in vb1.
Do anyone have an idea about how to solve this problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望组件在多个位置显示,那么它必须是副本,因为显示的是组件本身。 为什么需要组件是单例的? 仅仅是底层数据需要来自同一个地方吗? 在这种情况下,您只需将显示组件引用到同一条数据即可。
如果您确实需要在多个位置使用相同的组件,则每次显示时都必须移动它。
例如:
If you want the component to be displayed at multiple places, then it will have to be copies, since it is the component itself that is displayed. Why do you need the component to be a Singleton? Is it only the underlying data that needs to come from the same place? In that case, you can just refer the display components to the same piece of data.
If you really do need the same component in multiple places, you will have to move it around whenever it is displayed.
Eg: