Find and Replace Library Names and Linkages using JSFL

Another script to save programmer’s fingers. It replaces words in library, including linkages and package names. Case sensitive. So, if you want to replace all class linkages from the package “com.test1″ to “com.test1.specific”, it’s an instant. It asks which is the word to substitute, and by which word. Hit ok, and it’s done.

  1. function find_and_replace_in_library(){
  2.  
  3.   var substitute=prompt(‘What is the word to substitute?’);
  4.   var newterm=prompt(‘By which word?’);
  5.   if(substitute==null || newterm==null){
  6.     return;
  7.   }
  8.  
  9.   for( var h = 0; h < fl.getDocumentDOM().library.items.length; h++){
  10.     var item=fl.getDocumentDOM().library.items[h];
  11.    
  12.     //search for item name
  13.     var full_item_name=item.name;
  14.     var item_folder=full_item_name.substr(0,full_item_name.lastIndexOf(‘/’));
  15.     var clean_item_name=full_item_name.substr(full_item_name.lastIndexOf(‘/’)+1);   
  16.     var old_name=clean_item_name;
  17.     var new_name=;
  18.     var exploded=old_name.split(substitute);
  19.     for(var i=0; i<exploded.length; i++){
  20.       if(i!=0){
  21.         new_name+=newterm;
  22.       }
  23.       new_name+=exploded[i];
  24.     }
  25.     if(old_name!=new_name){
  26.       item.name=new_name;
  27.     }
  28.    
  29.     //search for linkage
  30.     if(item.itemType==‘movie clip’){
  31.       if(item.linkageClassName!= && item.linkageClassName!=undefined && item.linkageClassName!=null){
  32.         var old_name=item.linkageClassName;
  33.         var new_name=;
  34.         var exploded=old_name.split(substitute);
  35.         for(var i=0; i<exploded.length; i++){
  36.           if(i!=0){
  37.             new_name+=newterm;
  38.           }
  39.           new_name+=exploded[i];
  40.         }
  41.         if(old_name!=new_name){
  42.           item.linkageClassName=new_name;
  43.         }
  44.       }
  45.     }
  46.   }
  47. }
  48.  
  49. find_and_replace_in_library();

Click here to download

This entry was posted in JSFL and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

  1. [...] Find and replace library names and linkages using JSFL [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>