Kyle Ward: Flex, AIR, Flash Developer.   
  • Home
  •  

    JSFL to export multiple swf’s from a fla

    October 15th, 2010

    I am in the process of updating about 250 swfs for our clients. Luckily they all use the same fla, the only difference being the values of the variables on the first frame.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    var naam:String =   "timbucktwo"; // naam == name
    var type:String =   "school"; //"club" or "school"
    var website:String =  "www.timbucktwo.co.za";
    /********************************************
    *       do not edit below this line         *
    *********************************************/

    import com.d6communicator.Communicator;
    import com.d6technology.constants.communicator.CommunicatorConstants;
    var communicator:Communicator = new Communicator(this,naam,type,website);

    In order to make this process alot simpler and reusable i created a JSFL document which when runs:

    1. Loops through an array of items
    2. Updates the code in the first frame of the open fla
    3. Exports an item specific SWF
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    var SAVE_DIR = "file:///C|/Documents and Settings/kyleward/Desktop/communicatorsUpdates/";
    var SAVE_FILE = "communicator.swf";

    var items = [
        ["ahmp", "school", "www.ahmp.co.za"],
        ["AHS", "school", "www.rooiskool.co.za"],
        ["allenglen", "school", "www.allenglen.co.za"],
        ["a_convent", "school", "www.assumptionconvent.co.za"],
        ["barkly_p", "school", "www.barklyhouse.org.za"],
        ["bcobbeek", "school", "www.bs-cobbeek.nl"],
        ["basisschool", "school", "www.bsgerardusmajella.nl"],
        ["bayprim", "school", "www.bayprimary.co.za"],
        ["beaumont_p", "school", "www.beaumont4u.co.za"],
        ["bellvilleh", "school", "www.bellvillehigh.co.za"],
        ["bigsisters", "club", "www.d6technology.com"],
        ["boland", "school", "www.bolandlandbou.co.za"],
        ["brescia", "school", "www.brescia.co.za"],
        ["bundi", "school", "www.d6technology.com"],
        ["carpediem", "school", "www.d6technology.com"],
        ["charlo_p", "school", "www.charlo.co.za"],
        ["chelsea_p", "school", "www.cdsp.co.za"],
        ["c_robin", "school", "www.d6technology.com"],
        ["waldorf", "school", "www.waldorfconstantia.org.za"],
        ["cordwalles_prep", "school", "www.cordwalles.co.za"],
        ["cornwallhill", "school", "www.cornwall.co.za"],
        ["crawfordc_lalucia", "school", "www.crawford.co.za"],
        ["crawford_lonehill", "school", "www.crawford.co.za"],
        ["crawford_northcoast", "school", "www.crawford.co.za"],
        ["crawford_college_pretoria", "school", "www.crawford.co.za"],
        ["crawfordc_sandton", "school", "www.crawfordschools.co.za"],
        ["crawprep_f", "school", "www.crawfordschools.co.za/prep/fourways/home/prep.html"],
        ["crawfordprep_lalucia", "school", "www.crawfordschools.co.za"],
        ["crawfordprep_nc", "school", "www.crawfordschools.co.za"],
        ["crawfordpretoria_p", "school", "www.crawfordschools.co.za"],
        ["crawprep_s", "school", "www.crawfordschools.co.za/prep/sandton/home/prep.html"],
        ["crawpp_f", "school", "www.crawfordschools.co.za/pre/fourways/home/preprimary.html"],
        ["currolangebaan", "school", "langebaan.curro.co.za"],
        ["d6school", "school", "www.school-communicator.com"],
        ["danville_gh", "school", "www.danville.kzn.school.za"],
        ["dehoop", "school", "www.dehoopps.co.za"],
        ["delasalle", "school", "www.delasalle.co.za"]
       ];
       
    process();
       
    function process()
    {
     var l = items.length;

     for (var i=0; i<l; i++)
     {
      processItem(items[i][0], items[i][1], items[i][2]);
     }
    }

    function processItem(naam,type,website)
    {
     var copy = returnScript(naam, type, website);
     var url = SAVE_DIR + naam.toUpperCase() + SAVE_FILE;

     fl.actionsPanel.setText(copy);
     fl.getDocumentDOM().exportSWF(url, false);
    }

    function returnScript(naam,type,website)
    {
     var output = ""
     
     output += 'var naam:String =   "'+naam+'"; // naam == name\n';
     output += 'var type:String =   "'+type+'"; //"club" or "school"\n';
     output += 'var website:String =  "'+website+'";\n';
     output += '/********************************************\n';
     output += '*       do not edit below this line         *\n';
     output += '*********************************************/\n';
     output += 'import com.d6communicator.Communicator;\n';
     output += 'import com.d6technology.constants.communicator.CommunicatorConstants;\n';
     output += 'var communicator:Communicator = new Communicator(this,naam,type,website);\n';
     
     return output;
    }

    Pagination on a Filtered ArrayCollection

    October 1st, 2010

    Thought this might be helpful as i couldn’t find a filtered example of pagination on Google.

    Simply i find a _minIndex and _maxIndex based on the galleryFilterVO.pagingIndex required as well as init an _index [initMinMax()].

    If the item successfully passes through the filterFunction “initial filter”, i then incremented the _index and see if it is in range of the _minIndex and _maxIndex.

    My ArrayCollection is now filtered to the specific data [in this case by categories] as well as been paginated.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     public class GalleryListFilterCommand extends Command
      {
      [Inject] public var galleryListVO:GalleryListVO;  
      [Inject] public var galleryFilterVO:GalleryFilterVO;
     
      private var _minIndex:int;
      private var _maxIndex:int;
      private var _index:int;

      override public function execute():void
      {
       initMinMax();
       applyFilter();
      }  
     
      /*PRIVATE METHODS*/
      private function initMinMax():void
      {
       //http://cookbooks.adobe.com/post_Paged_ArrayCollection-11083.html
       _maxIndex = 9 * (galleryFilterVO.pagingIndex + 1);
       _minIndex = _maxIndex - 9;
       _index = -1;
      }
     
      private function applyFilter():void
      {
       galleryListVO.list.filterFunction = filterFunction;
       galleryListVO.list.refresh();  
      }
     
      private function filterFunction(item:GalleryListItemVO):Boolean
      {
       var output:Boolean = true;
       
       if (galleryFilterVO.categoryVO.id != Constants.SELECT_ALL)
       {
        output = (item.categoryID == galleryFilterVO.categoryVO.id);
       }
       
       if (output)
       {
        _index++;
       
        output = _minIndex <= _index && _index < _maxIndex;
       }
       
       return output;
      }
     }