0 Replies Latest reply on Apr 6, 2009 12:49 AM by essa tkinen

    dynamically populate a sort fields array?

    essa tkinen

      so i'm having a problem i want to make my sorting dynamic so which ever sorts are being used get put into the mySort.fields array. I don't no how to get sortsString(a comma delimted list) to excute before mySort.fields . Anybody got an idea? Its probably something stupid and small that i don't no

       

      private function applySort(item:String):void {

      var sorts:ArrayCollection = new ArrayCollection;

      var mySort:Sort = new Sort();

      trace(item);

      switch (item) {

      case 'mostViewsSort':

      var field1:SortField = new SortField("views", true,true,true);

      sorts.addItem('field1');

      break;

      case 'mostDownloadsSort':

      var field2:SortField = new SortField("downloads", true,true,true);

      sorts.addItem('field2');

      break;

      case 'adminRatingSort':

      var field3:SortField = new SortField("adminRating", true,true,true);

      sorts.addItem('field3');

      break;

      case 'userRatingSort':

      var field4:SortField = new SortField("userRating", true,true,true);

      sorts.addItem('field4');

      break;

      }

      var sortsString:String = String(sorts);

       

      mySort.fields=[sortsString];         // getting an error here if I just put in field1 it works fine but i want to apply field1,field2 etc if user wants it and that gets stored in the sorts array and gets put into sortsString as a comma delimted list.

      _videos.sort = mySort;

      _videos.refresh();

      sorts.removeAll();

       

      }