• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Swap single line of text across 70 projects

Community Beginner ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

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

Views

274

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2023 Jul 13, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 14, 2023 Jul 14, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2023 Jul 14, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 14, 2023 Jul 14, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 17, 2023 Jul 17, 2023

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines