jcsfrei
asked on
automate find replace export
Hi all
I have a big collection of .fla files. Many of them have links to a special path on an actionscript in a button, through a window.open javascript call like window.open('../../../dire ctory/file .htm')
But now I must change this path in all files to something like window.open('../directory/ file.htm') . Unfortunately, I cant change the directory hierarchy to avoid changing the fla files.
Is there a way to automate this task?
I´ve read a few lines about jsfl, that you can see the history of your actions and so, but find/replace commands don't appear in history. Then I got lost in a huge api.
Using jsfl or even plain actionscript, is there a way of looping through all fla files in a given path, replace all ocurrences of the javascript call in each file and then export the swf of the modified fla, saving the files, instead of doing all this by hand? If possible, can you give any directions, hints, code snipets?
Best regards, JC
I have a big collection of .fla files. Many of them have links to a special path on an actionscript in a button, through a window.open javascript call like window.open('../../../dire
But now I must change this path in all files to something like window.open('../directory/
Is there a way to automate this task?
I´ve read a few lines about jsfl, that you can see the history of your actions and so, but find/replace commands don't appear in history. Then I got lost in a huge api.
Using jsfl or even plain actionscript, is there a way of looping through all fla files in a given path, replace all ocurrences of the javascript call in each file and then export the swf of the modified fla, saving the files, instead of doing all this by hand? If possible, can you give any directions, hints, code snipets?
Best regards, JC
also, might want to add logging to this code. "objDoc.close()" after save will close documents - missed that!
-gaurav
-gaurav
ASKER
Hey gaurav
Thanks for your reply. I was already working on the code since no one answered. With your answer, I improved my code. It searches through library and main timeline, has a flag to search only in the last frame or on all frames and a few twaeks. I'm working on an interface to put it as an extension.
Looks like this
FolderPath="file://c|/temp /";
findStr="../../test";
replaceStr="../test";
allframes=false;
if (FLfile.exists(FolderPath) ){
currFolder=FolderPath;
URI = currFolder+"log.txt";
FLfile.write(URI,"Start\r\ n");
var files = FLfile.listFolder(currFold er+"*.fla" , "files");
for(var f=0;f<files.length;++f) {
fl.openDocument(currFolder +files[f]) ;
FLfile.write(URI,":::"+cur rFolder+fi les[f]+"\r \n","appen d");
if (doTimelines()){
fl.getDocumentDOM().save(t rue);
fl.getDocumentDOM().publis h();
}
fl.getDocumentDOM().close( false);
}
FLfile.write(URI,":::End of folder contents.\r\n","append");
} else {
alert("Folder not found.");
}
function doTimelines(){
var found=false;
if (sweepTimeline(fl.getDocum entDOM(),0 )) found=true;
var tline;
for(var i = 0; i < fl.getDocumentDOM().librar y.items.le ngth; i++){
tline= fl.getDocumentDOM().librar y.items[i] ;
if (sweepTimeline(tline,1)) found=true;
}
return found;
}
function sweepTimeline(n, isItem){
var myTLine;
var found=false;
if (n.itemType=="video" || (n.itemType==undefined && isItem==1) || n.itemType=="folder" || n.itemType=="font" || n.itemType=="sound"
|| n.itemType=="bitmap" || n.itemType=="compiled clip") return found;
if (isItem==1) { myTLine=n.timeline;}
else {myTLine=n.getTimeline();}
for(var i = 0; i < myTLine.layers.length; i++){
var myLayers = myTLine.layers[i];
if (myLayers.layerType!="norm al") continue;
var j=myLayers.frames.length-1 ;
if (allframes) j=0;
for (;j<myLayers.frames.length ;j++){
var myFrames = myLayers.frames[j];
//test actionscript in frame
if (myFrames.actionScript!=un defined){
if (myFrames.actionScript.ind exOf(findS tr)>=0){
found=true;
if (isItem==1){
fl.getDocumentDOM().librar y.editItem (myTLine.n ame);
}
myFrames.actionScript=myRe place(myFr ames.actio nScript,fi ndStr,repl aceStr);
FLfile.write(URI,myFrames. actionScri pt+"\r\n__ __________ __________ __________ _____\r\n" ,"append") ;
}
}
//test actionscript in each element in the frame
for(var k = 0; k <myFrames.elements.length; k++){
var myObj = myFrames.elements[k];
if (myObj!=undefined){
if (myObj.actionScript!=undef ined){
if (myObj.actionScript.indexO f(findStr) >=0){
found=true;
if (isItem==1){
fl.getDocumentDOM().librar y.editItem (myTLine.n ame);
}
myObj.actionScript=myRepla ce(myObj.a ctionScrip t,findStr, replaceStr );
FLfile.write(URI,myObj.act ionScript+ "\r\n_____ __________ __________ __________ __\r\n","a ppend");
}
}
}
}
}
}
return found;
}
function myReplace(str, c1, c2) {
while (str.indexOf(c1)>=0){
tmp0=str.slice(0,str.index Of(c1))
tmp1=str.slice(str.indexOf (c1)+c1.le ngth,str.l ength);
str=tmp0+c2+tmp1;
}
return str;
}
Problem: timeout alerts on a folder with many files and searches only on one timeline of the film, if it has many scenes, I thnk it does not scan all of them.
The timeout problem I'm trying to solve creating an swf that integrates the jsfl commands, but is very difficult to use actionscript and jsfl mixed together. I could not find any documentation that shows how do it. With an swf, I could use a tool that increases the timeout time.
Any thoughts?
Thanks, JC
Thanks for your reply. I was already working on the code since no one answered. With your answer, I improved my code. It searches through library and main timeline, has a flag to search only in the last frame or on all frames and a few twaeks. I'm working on an interface to put it as an extension.
Looks like this
FolderPath="file://c|/temp
findStr="../../test";
replaceStr="../test";
allframes=false;
if (FLfile.exists(FolderPath)
currFolder=FolderPath;
URI = currFolder+"log.txt";
FLfile.write(URI,"Start\r\
var files = FLfile.listFolder(currFold
for(var f=0;f<files.length;++f) {
fl.openDocument(currFolder
FLfile.write(URI,":::"+cur
if (doTimelines()){
fl.getDocumentDOM().save(t
fl.getDocumentDOM().publis
}
fl.getDocumentDOM().close(
}
FLfile.write(URI,":::End of folder contents.\r\n","append");
} else {
alert("Folder not found.");
}
function doTimelines(){
var found=false;
if (sweepTimeline(fl.getDocum
var tline;
for(var i = 0; i < fl.getDocumentDOM().librar
tline= fl.getDocumentDOM().librar
if (sweepTimeline(tline,1)) found=true;
}
return found;
}
function sweepTimeline(n, isItem){
var myTLine;
var found=false;
if (n.itemType=="video" || (n.itemType==undefined && isItem==1) || n.itemType=="folder" || n.itemType=="font" || n.itemType=="sound"
|| n.itemType=="bitmap" || n.itemType=="compiled clip") return found;
if (isItem==1) { myTLine=n.timeline;}
else {myTLine=n.getTimeline();}
for(var i = 0; i < myTLine.layers.length; i++){
var myLayers = myTLine.layers[i];
if (myLayers.layerType!="norm
var j=myLayers.frames.length-1
if (allframes) j=0;
for (;j<myLayers.frames.length
var myFrames = myLayers.frames[j];
//test actionscript in frame
if (myFrames.actionScript!=un
if (myFrames.actionScript.ind
found=true;
if (isItem==1){
fl.getDocumentDOM().librar
}
myFrames.actionScript=myRe
FLfile.write(URI,myFrames.
}
}
//test actionscript in each element in the frame
for(var k = 0; k <myFrames.elements.length;
var myObj = myFrames.elements[k];
if (myObj!=undefined){
if (myObj.actionScript!=undef
if (myObj.actionScript.indexO
found=true;
if (isItem==1){
fl.getDocumentDOM().librar
}
myObj.actionScript=myRepla
FLfile.write(URI,myObj.act
}
}
}
}
}
}
return found;
}
function myReplace(str, c1, c2) {
while (str.indexOf(c1)>=0){
tmp0=str.slice(0,str.index
tmp1=str.slice(str.indexOf
str=tmp0+c2+tmp1;
}
return str;
}
Problem: timeout alerts on a folder with many files and searches only on one timeline of the film, if it has many scenes, I thnk it does not scan all of them.
The timeout problem I'm trying to solve creating an swf that integrates the jsfl commands, but is very difficult to use actionscript and jsfl mixed together. I could not find any documentation that shows how do it. With an swf, I could use a tool that increases the timeout time.
Any thoughts?
Thanks, JC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey gaurav
with your help I was able to fix and improve my code, and integrate the jsfl with action script. In the end, I managed to loop through all my flash files, change what I needed, exported the new swf files, generated a log file to track changes, saved the changed fla files and learned a lot about jsfl and flash extensions. Even managed to make my own panel and now its a default extension for the flash developers that work with me.
Thanks a lot for your help, a well deserved grade A.
Best, JC
with your help I was able to fix and improve my code, and integrate the jsfl with action script. In the end, I managed to loop through all my flash files, change what I needed, exported the new swf files, generated a log file to track changes, saved the changed fla files and learned a lot about jsfl and flash extensions. Even managed to make my own panel and now its a default extension for the flash developers that work with me.
Thanks a lot for your help, a well deserved grade A.
Best, JC
it is certainly possible ussing jsfl - however it is not simple. the find and replace is not accesible to jsfl without a hack. for starters one can use code given below. the code is not complete neither have i run it ( have just typed in notepad :) ) if you have multiple timlines then one will have to add a loop for timelines. also, if the buttons are nested into other clips then one will have add a loop for items in library. hope this helps.
-gaurav
function replace(strContent)
{
strContent.replace(/'..\/.
}
function scanLayers(arrLayers)
{
for(var i = 0; i < arrLayers.length ;i++)
{
var objLayer = arrLayers[i];
for(var j = 0; j < objLayer.frames.length; j++)
{
var objFrame = objLayer.frames[j];
replace(objFrame.actionScr
for(var k = 0; k < objFrame.elements.length; k++)
{
var objInstance = objFrame.elements[k];
if(objInstance.elementType
objInstance.instanceType == "symbol")
{
replace(objInstance.action
}
}
}
}
}
function main()
{
var strPath = "file:///c:/mypath/";
var arrFiles = FLfile.listFolder(strPath + "*.fla","files");
for(var i = 0; i < arrFiles.length ;i++)
{
var objDoc = fl.openDocument(strPath + arrFiles[i]);
scanLayers(objDoc.timeline
objDoc.save();
objDoc.publish();
}
}
main();