-
1. Re: fl.saveDocument()
Prpl_Ppl_Etr Dec 6, 2012 11:48 AM (in response to community help)Perhaps someone could explain why this function ignores certain changes when it saves. Below is some .jsfl code to reproduce the issue.
var originalInstanceName="originalInstanceName";
var newInstanceName="newInstanceName";
var sampleText="Foo.";
// create the new Document
var doc=fl.createDocument('timeline');
// add a text field
// it's ridiculous that:
// a) you can't name the instance in this function
// ...and/or...
// b) this method doesn't return a reference to the text field, so you can't name the instance that way either!
doc.addNewText( ,sampleText);
// name the instance
// hard to believe that this is the only way to find and name an instance
var tf=doc.getTimeline().layers[0].frames[0].elements[0];
tf.name=originalInstanceName;
// save and close the docmuent
fl.saveDocumentAs(doc);
fl.closeDocument(doc);
// now reopen the document
var fileURI = fl.browseForFileURL('open',"Select the document you just created");
var savedDoc=fl.openDocument(fileURI);
// rename the text field
var instanceObjects=fl.findObjectInDocByName(originalInstanceName, savedDoc);
for(var i=0;i<instanceObjects.length;i++){
var instanceObject=instanceObjects[i];
var instance=instanceObject.obj;
instance.name=newInstanceName;
}
// save and close the document
fl.saveDocument(savedDoc);
fl.closeDocument(savedDoc);
// INSTANCE NAME HAS NOT CHANGED!!!
</code>
-
2. Re: fl.saveDocument()
saurav_wap Dec 6, 2012 11:50 PM (in response to community help)Hi ,
Actually the instance name is getting changed but the document is not getting dirty . Since the document is not modified even though you are saving the document by running the command fl.saveDocument(savedDoc) , the changes are not reflected when you open the document . You can comment out fl.closeDocument(savedDoc); and after the script is executed you can see the instance name has changed but the document is not dirtied i.e asterisk sign does not appear on the title bar of the document .
Workaround --> Before fl.saveDocument(savedDoc); execute some command that will dirty your document such as change the text font or size or content and and then it should work fine
Thanks
