3 Replies Latest reply on Mar 17, 2007 2:32 PM by xmrcivicboix

    Cairngorm Events

    xmrcivicboix
      I just picked up on Cairngorm and it seems somewhat confusing. I hope someone would help me clarify this. I have an Array of files that I would like to import. How can I execute each command without manually creating those commands and delegates for each of those file. In the end result, I would probably have more than just 2 files, maybe 100's.

      private var _file:Array = new Array("file1.xml","file2.xml");

      private function importFiles(): void
      {
      for each (var item:String in _files)
      {
      var event:ItunesEvent = new ItunesEvent(item);
      CairngormEventDispatcher.getInstance().dispatchEvent(event);
      }
      }

      What I basically want to happen is that when "file1.xml" is done importing, run the same command again to import "file2.xml", so on and so forth.

      Thanks.
        • 1. Cairngorm Events
          ChickenSupreme
          Im no programmer but here goes, in the resulthandler for the command dispatch an event to import the next file in the array. you could keep a copy of the array in the model and remove the item from the array after importing. Hope that helps
          • 2. Re: Cairngorm Events
            xmrcivicboix Level 1
            Thanks for the quick reply. So you're saying that my _files array should be stored in a model then in my result handler call then next file in line?

            public function result(data:Object): void
            {
            var event:ResultEvent = data as ResultEvent;
            var list:XMLList = new XMLList(event.result);
            util.iTunesParser(list);
            model.selectedTab = model.LIBRARY;

            //shift off the array
            model.file.shift();
            if (model.file.length != 0)
            {
            var event:ItunesEvent = new ItunesEvent(file[0]);
            CairngormEventDispatcher.getInstance().dispatchEvent(event);
            }
            }
            • 3. Re: Cairngorm Events
              xmrcivicboix Level 1
              nice.... seems like what I just wrote worked. What I did was create an Array called 'fileList' in my model.

              then in the initial start I have this:

              private var _playListPath:Array;

              for each (var item:String in _playListPath)
              {
              model.fileList.push(item);
              }

              var event:ItunesEvent = new ItunesEvent(model.fileList[0]);
              CairngormEventDispatcher.getInstance().dispatchEvent(event);

              Then in my command:

              model.fileList.shift();
              if (model.fileList.length != 0)
              {
              var e:ItunesEvent = new ItunesEvent(model.fileList[0]);
              CairngormEventDispatcher.getInstance().dispatchEvent(e);
              }