创建循环以将变量发送到 Flex 中的其他组件

发布于 2024-08-14 01:35:47 字数 1642 浏览 3 评论 0原文

我在 Flex 中有一些简单的函数,我想将其中一个变量发送到我的应用程序中使用的所有组件...问题是我的应用程序中有很多组件,我不知道如何引用我的组件的 id...基本上,有没有更简单的方法来做到这一点;

private function preloadStuff():void{

    // populating of bulkLoader var

    var preloaderItemsList:XMLListCollection = new XMLListCollection(preloaderItems.children());
    var item:XML;
    for each (item in preloaderItemsList){
        bulkLoader.add(item.path.toString(), {id:item.swfid.toString()});
    }
    bulkLoader.addEventListener(BulkLoader.PROGRESS, bulkProgress);
    bulkLoader.addEventListener(BulkLoader.COMPLETE, bulkComplete);
    bulkLoader.start();

    // sending bulkLoader to all of components
    // component ids are _01, _02, _03, etc.

    _01.bulk = bulkLoader;
    _02.bulk = bulkLoader;
    _03.bulk = bulkLoader;
    _04.bulk = bulkLoader;
    _05.bulk = bulkLoader;
    _06.bulk = bulkLoader;
    _07.bulk = bulkLoader;
    _08.bulk = bulkLoader;
    _09.bulk = bulkLoader;
    _10.bulk = bulkLoader;
    _11.bulk = bulkLoader;
    _12.bulk = bulkLoader;
    _13.bulk = bulkLoader;
    _14.bulk = bulkLoader;
    _15.bulk = bulkLoader;
    _16.bulk = bulkLoader;
    _17.bulk = bulkLoader;
    _18.bulk = bulkLoader;
    _19.bulk = bulkLoader;
    _20.bulk = bulkLoader;
    _21.bulk = bulkLoader;
    _22.bulk = bulkLoader;
    _23.bulk = bulkLoader;
    _24.bulk = bulkLoader;
    _25.bulk = bulkLoader;
    _26.bulk = bulkLoader;
    _27.bulk = bulkLoader;
    _28.bulk = bulkLoader;
    _29.bulk = bulkLoader;
    _30.bulk = bulkLoader;
    _31.bulk = bulkLoader;
    _32.bulk = bulkLoader;
    _33.bulk = bulkLoader;
    _34.bulk = bulkLoader;

}

非常感谢您的帮助!

I have some simple function in Flex in which I would like to send one of my variables to all the components used in my app... The problem is that there is lots of components in my app, and I'm not sure how to reference to my component's id... Basically, is there an easier way to do this;

private function preloadStuff():void{

    // populating of bulkLoader var

    var preloaderItemsList:XMLListCollection = new XMLListCollection(preloaderItems.children());
    var item:XML;
    for each (item in preloaderItemsList){
        bulkLoader.add(item.path.toString(), {id:item.swfid.toString()});
    }
    bulkLoader.addEventListener(BulkLoader.PROGRESS, bulkProgress);
    bulkLoader.addEventListener(BulkLoader.COMPLETE, bulkComplete);
    bulkLoader.start();

    // sending bulkLoader to all of components
    // component ids are _01, _02, _03, etc.

    _01.bulk = bulkLoader;
    _02.bulk = bulkLoader;
    _03.bulk = bulkLoader;
    _04.bulk = bulkLoader;
    _05.bulk = bulkLoader;
    _06.bulk = bulkLoader;
    _07.bulk = bulkLoader;
    _08.bulk = bulkLoader;
    _09.bulk = bulkLoader;
    _10.bulk = bulkLoader;
    _11.bulk = bulkLoader;
    _12.bulk = bulkLoader;
    _13.bulk = bulkLoader;
    _14.bulk = bulkLoader;
    _15.bulk = bulkLoader;
    _16.bulk = bulkLoader;
    _17.bulk = bulkLoader;
    _18.bulk = bulkLoader;
    _19.bulk = bulkLoader;
    _20.bulk = bulkLoader;
    _21.bulk = bulkLoader;
    _22.bulk = bulkLoader;
    _23.bulk = bulkLoader;
    _24.bulk = bulkLoader;
    _25.bulk = bulkLoader;
    _26.bulk = bulkLoader;
    _27.bulk = bulkLoader;
    _28.bulk = bulkLoader;
    _29.bulk = bulkLoader;
    _30.bulk = bulkLoader;
    _31.bulk = bulkLoader;
    _32.bulk = bulkLoader;
    _33.bulk = bulkLoader;
    _34.bulk = bulkLoader;

}

Thank you very much for any help!

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

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

发布评论

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

评论(2

慕烟庭风 2024-08-21 01:35:47

您可以引发一个自定义事件(冒泡)并让所有组件监听它。

You can raise a custom Event (which bubbles) and have all your components to listen to it.

浸婚纱 2024-08-21 01:35:47

对此有很多解决方案,您可以简单地制作一个字典并存储您想要通过的每个实例(我认为这是最好的方法),或者您可以直接实现这个:

for (var i = 1; i <= lastId; i++) // being lastId the last id of you components
    this["_" + (i < 10 ? "0"+i : i)].bulk = bulkLoader;

this["property"] // is the same that this.property

它令人毛骨悚然且非常可怕,但它回答了您的问题。

There are many solutions to this, you can simply make a Dictionary and store every instance that you want to pass trough (i think this is the best way) or you can just implement this:

for (var i = 1; i <= lastId; i++) // being lastId the last id of you components
    this["_" + (i < 10 ? "0"+i : i)].bulk = bulkLoader;

this["property"] // is the same that this.property

It's creepy and very awful but it answer your question.

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