获取动态生成的 Flex 组件的句柄

发布于 2024-08-10 12:05:30 字数 339 浏览 7 评论 0原文

我有一个 Flex 应用程序,它引用一个单独的 MXML 文件作为自定义组件的模板。我在程序中多次动态创建该组件的实例,但我需要获得一个句柄,该句柄允许我根据需要修改该组件的实例。

我在实例化时使用组件的 MXML 文件中的可绑定公共变量将特定信息传递给该组件。我使用 addChild() 将其添加到我的主程序中。

我想根据需要更新组件的进度条,并且想将其从添加子项的框中删除。

获取变量的最简单/最好的方法是什么,该变量将使我能够对每个组件进行可预测的访问,以便我可以根据需要轻松地操作组件?一些研究表明创造已经完成,但我认为直接询问比进行大量不同的实验却一无所获更快。

感谢您的所有帮助。 :)

I have a Flex application which references a separate MXML file as a template for a custom component. I create instances of the component dynamically several times in my program, but I need to get a handle that will allow me to modify that instance of the component as desired.

I pass specific information to this component on instantiation using bindable public variables in the component's MXML file. I add it to my main program using addChild().

I want to update the component's progressbar as necessary and I want to remove it from the box to which I addChild'd it.

What's the easiest/best way to get a variable that will give me predictable access to each component so I can easily manipulate the components as necessary? Some research suggests creationComplete, but I decided it was faster to just ask than to go through lots of different experiments and come up blank.

Thanks for all the help. : )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2024-08-17 12:05:30

你不能只将组件列表保存在数组中吗?当您创建它们并在其父级上调用 addChild() 时,大概您有一个对象引用。为什么不把它们同时放入一个数组中呢?

var list_of_controls:Array = new Array();
var new_Object:<yourType>;

new_Object = new <yourType>();
parent.addChild(new_Object);
list_of_controls.push(new_Object);

然后你就可以得到它们...

var my_Object:<yourType>;
for each (my_Object in list_of_controls)
{
    // do something
}

你必须确保完成后正确处理它们,因为数组中的引用将使它们保持存在直到清除。

如果您决定要使用 getChildren() 代替(您可以这样做),请花时间阅读文档,因为我认为它每次调用都会返回一个新数组。

我希望这有帮助。

Can you not just keep a list of your components in an array? Presumably you have an object reference when you create them and call addChild() on their parent. Why not just put them in an array at the same time?

var list_of_controls:Array = new Array();
var new_Object:<yourType>;

new_Object = new <yourType>();
parent.addChild(new_Object);
list_of_controls.push(new_Object);

then you can get at them...

var my_Object:<yourType>;
for each (my_Object in list_of_controls)
{
    // do something
}

You would have to make sure you dispose of them properly when you re done because the reference in your array would keep them in existence until cleared.

If you decide that you want to use getChildren() instead - which you could - take the time to read the documentation because I think it returns a new array with each call.

I hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文