سؤال

var tmpDoc = fl.createDocument();
/*..some logic...*/
tmpDoc.addItem({x:0,y:0},item);

My JSFL has the above code.
And on the 3rd line, I get a dialog box :
which has title : "Resolve library conflict"
two radio button options : "replace","dont replace"
two buttons : "ok","cancel"

Due to this dialog box, I have to manually monitor
the script execution and click on a button.

I want to either :
1. Suppress these kind of dialog boxex altogether.
2. or programatically provide a default option to these kind of dialogs.

How do I do it with JSFL?

هل كانت مفيدة؟

المحلول

You can try to check if the item exists before adding it to the library using library's itemExists() function:

var doc = fl.getDocumentDOM();
var lib = doc.library;
//check if the item already exists first, if so, keep count of symbols with the same name, append random, etc.
if(!lib.itemExists('item')) lib.addNewItem('movie clip','item');
else                        lib.addNewItem('movie clip','item'+Math.random());

HTH

نصائح أخرى

I was able to work around this. The trick is that when you add a new item, it lands at the top level of the library and looks for conflicts there, even if there is an "identical" item somewhere in a library folder.

And when you move a library item using JSFL (library.moveToFolder) to the location of the same item in a folder, the item is replaced, and no conflict dialog appears.

  1. If possible, manually move the library item that you want from the top level of the library into a folder. This is only done once and is a permanent change to your library structure.
  2. At script time, as you add each item to the document, call library.moveToFolder(folderPath, itemPath, true);
  3. This will overwrite the item in the folder and skip the prompt

Your exact approach may be different depending on your needs, but the key is to not have items at the top of the library while you are adding. Move them somewhere else first.

As usual bending over backwards for Flash! Hope this helps.

P.S., this also works for adding components to the library.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top