Skip to main content
Participating Frequently
Jul 13, 2023 3:11 PM UTC
Question

Swap single line of text across 70 projects

I'm working on a large set of display ads in various sizes. Say I wanted to swap the text "6 months" to say "3 months" across all projects, is there a way to do that dynamically, rather than having to open up and manually revise, publish, zip every single project? Perhaps a variable data field that I can access and replace in visual studio code?

 

Thanks

    This topic is closed to new replies. Start a new post to keep the conversation going.

    8 replies

    Legend
    Jul 14, 2023 5:45 PM UTC

    Anyone who's reusing the same text across that many different FLAs should really, really be loading it from a common external file.

    Translate
    Participating Frequently
    Jul 17, 2023 6:49 PM UTC

    I'm listening! Have any links to information explaining this process? I'm creating HTML5 ads, I suppose the loading method you mention works with this?

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jul 13, 2023 10:36 PM UTC

    Hi.

     

    Here is a script that is supposed to open multiple FLAs and replace whatever text occurrencies it finds in each document.

     

    Some notes:

    - Please test it on some dummy files first;

    - This script may work better if you run it from within a FLA file and not when viewing or editing the JSFL file.

     

    Please feel free to improve or fix it in any way needed.

     

    Replace Text in Multiple FLAs.JSFL script:

     

    var dom, dialog;
    
    function main()
    {	
    	var ui =
    	[
    		"<dialog title='Replace Text in Multiple FLAs' buttons='accept, cancel'>",
    			"<hbox>",
    				"<label value='Find:'/>",
    				"<textbox id='find' value='' width='200'/>",
    			"</hbox>",
    			"<hbox>",
    				"<label value='Replace:'/>",
    				"<textbox id='replace' value='' width='200'/>",
    			"</hbox>",
    			"<checkbox id='matchCase' label='Match case' align='left' checked='false'/>",
    			"<checkbox id='wholeWord' label='Whole word' align='left' checked='false'/>",
    			"<checkbox id='close' label='Close FLAs' align='left' checked='true'/>",
    			"<checkbox id='promptToClose' label='Prompt to close if needed' align='left' checked='false'/>",
    			"<checkbox id='logResults' label='Log results' align='left' checked='true'/>",
    			"<checkbox id='save' label='Save' align='left' checked='true'/>",
    			"<spacer/>",
    		"</dialog>"
    	];
    
    	dialog = fl.xmlPanelFromString(ui.join(""));
    		
    	if (dialog.dismiss === "accept" && dialog.find !== "")
    		openFiles();
    }
    
    function openFiles()
    {
    	var uri = fl.browseForFolderURL("select", "Select the folder containing the FLAs.");		
    	var files = FLfile.listFolder(uri + "/*.fla", "Files.");
    	
    	if (files.length === 0)
    		return;
    	
    	try
    	{
    		var i;
    		
    		for (i = 0, total = files.length; i < total; i++)
    		{
    			fl.openDocument(uri + "/" + files[i]);
    			dom = fl.getDocumentDOM();
    			findAndReplace();
    			
    			if (dialog.save === "true")
    				dom.save();
    						
    			if (dialog.close === "true")
    				dom.close(dialog.promptToClose === "true");
    		}
    	}
    	catch(error)
    	{
    		if (dialog.logResults === "true")
    		{
    			fl.trace(files[i]);
    			fl.trace(error);
    			fl.trace("___________");
    		}
    	}
    }
    
    function findAndReplace()
    {
    	var results = fl.findObjectInDocByType("text", dom);
    	var total = results.length;
    
    	if (total > 0)
    	{
    		var pattern = dialog.wholeWord === "true" ? "\\b" + dialog.find + "\\b" : dialog.find;
    		var modifiers = dialog.matchCase === "true" ? "g" : "ig";
    		var regEx = new RegExp(pattern, modifiers);
    		var i, obj;
    		
    		for (i = 0; i < total; i++)
    		{
    			obj = results[i].obj;
    			obj.setTextString(obj.getTextString().replace(regEx, dialog.replace));
    		}
    
    		if (dialog.logResults === "true")
    		{
    			fl.trace(dom.name + ": Found " + total + " text field(s).");
    			fl.trace("");
    		}
    	}
    	else
    	{
    		if (dialog.logResults === "true")
    			fl.trace("Failed to find text field(s) in " + dom.name + ".");
    	}
    }
    
    main();

     

     

    Source / script / download:

    https://bit.ly/3pKlPJX

     

    I hope it helps.

     

    Regards,

    JC

    Translate
    Participating Frequently
    Jul 14, 2023 4:32 PM UTC

    Will this script be any different the opening all of the project files and using the native Find and Replace tool inside of Animate? 

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jul 14, 2023 4:51 PM UTC

    The difference is that the script will open all files, replace all the occurrences, save, and close.

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 13, 2023 3:19 PM UTC

    with jsfl and it's probably possible, but unless there are scores of files it's probably not worth it.

    Translate
    Participating Frequently
    Jul 13, 2023 3:44 PM UTC

    Currently 70 projects to revise. Plus, these display ads are an ongoing thing at my work. We will launch a campaign that uses the same visual theme across all the ads but include a different price offer for areas with different pricing. A solution to this would save a ton of time. I'll look into jsfl, thanks.

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 13, 2023 6:10 PM UTC

    you're welcome.

    Translate