创建循环以将变量发送到 Flex 中的其他组件
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以引发一个自定义事件(冒泡)并让所有组件监听它。
You can raise a custom Event (which bubbles) and have all your components to listen to it.
对此有很多解决方案,您可以简单地制作一个字典并存储您想要通过的每个实例(我认为这是最好的方法),或者您可以直接实现这个:
它令人毛骨悚然且非常可怕,但它回答了您的问题。
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:
It's creepy and very awful but it answer your question.