多个自定义组件和显示列表
我在同一个 SWF 上使用同一自定义组件的多个实例。该组件本质上只是一个具有特殊尺寸要求的文本字段。我还有另一个“包装器”组件,用于处理来自文本字段组件的信息。我最初计划使用阶段索引将数据与其来源的文本字段组件关联起来。这变得比我预想的更复杂。 当我从包装器跟踪时,我无法获取文本字段组件的索引。因此,我在组件代码中获取了它,并通过自定义事件将其与信息一起发送到包装器。问题是我无法区分哪个组件是哪个组件,因为它们的索引相同。我还可以看到组件垫片以及文本字段。我只是对编程组件如何在显示列表上工作感到非常困惑。
我的主要问题。有没有更好的方法将信息与正确的组件关联起来? 我想这是我唯一的问题。请为我指明正确的方向。
编辑:我忘记添加我的组件需要拖到舞台上。非常感谢您的回答,但它仅适用于以编程方式添加组件。任何帮助将不胜感激。即使它只是一个可能的解决方案或信息的链接,可以帮助我解决问题。再次感谢。
编辑2:我创建了一个虚拟占位符组件,它只绘制一个矩形,然后在运行时将其替换为以编程方式生成的文本字段组件。非常感谢所有帮助我找到这个解决方案的人。如果我想出更好的东西,我会更新这个。
I am using several instances of the same custom component on the same SWF. The component is essentially just a textfield with special sizing requirements. I also have another "wrapper" component that deals with the info from the textfield components. I was initially planning on using the stage index to associate the data with the textfield component it came from. This became more complicated than I anticipated.
When I trace from the wrapper i can't get the index of the textfield components. So I got it in the component code and sent it with the info to the wrapper via a custom event. The problem there is that i can't tell which component is which because they are indexed identically. I can also see the component shim as well as the textfield.I'm just really confused about how programmatic components work on the display list.
My main Question. Is there a better way to associate the info with the proper component?
I guess that's my only question. Please point me in the right direction.
EDIT: I forgot to add that my components are required to be dragged on to stage. Thanks so much for the answer but it will only work for adding the components programmatically. Any help would be greatly appreciated. Even if it's just a link to a possible solution or info that will help me sort it out. Thanks again.
EDIT2: I created a dummy place-holder component that just draws a rectangle then at runtime replaces it with programmatically generated textfield component. So Thanks so much for everyone that helped me on my way to this solution. If I come up with something better I'll update this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为每个 TextField 指定一个唯一的名称,如下所示:
例如
txt[99] = stage.getChildByName("txt_" + 99)
;...或者您可以使用数组或向量来保存对每个文本字段的引用。
You could give each TextField a unique name, like so:
where for example
txt[99] = stage.getChildByName("txt_" + 99)
;... or you could use an Array or Vector to hold a reference to each TextField.