views:

231

answers:

2

Hi!
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!

+1  A: 

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

Chetan Sastry
A: 

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.

unkiwii