Skip to main content
Known Participant
April 18, 2023
Question

jsfl to be fixed

  • April 18, 2023
  • 3 replies
  • 987 views

Use jsfl to adjust all movie clips to graphic elements

// Loop through all the library items
for (var i = 0; i < fl.getDocumentDOM().library.items.length; i++) {
  var item = fl.getDocumentDOM().library.items[i];

  // Check if the item is a movie clip
  if (item.itemType === "movie clip") {
    // Convert movie clip to a graphic element
    fl.getDocumentDOM().convertToSymbol(item.name, "graphic");
  }
}

// Refresh the library to reflect changes
fl.getDocumentDOM().library.editItem();
This topic has been closed for replies.

3 replies

Multoman
Inspiring
April 18, 2023

If you need to process all the elements, then this can be done by the timeline object of each character individually. You can get this object from the library element

// Loop through all elements on the stage
var doc = fl.getDocumentDOM();
var items = doc.library.items


for (var n = 0; n < items.length; n++) {
	var item = doc.library.items[n]
	if (item.itemType === "movie clip" || item.itemType === "graphic" || item.itemType === "button") {
		var timeline = item.timeline
		for (var i = 0; i < timeline.layers.length; i++) {
			var layer = timeline.layers[i];
			for (var j = 0; j < layer.frames.length; j++) {
				var frame = layer.frames[j];
				var elements = frame.elements;
				for (var k = 0; k < elements.length; k++) {
					var element = elements[k];

					// Check if the element is a symbol
					if (element.elementType === "instance") {
						// Adjust properties of the symbol
						element.symbolType = "graphic";
						// Additional property adjustments can be made here

					}
				}
			}
		}
	}
}
kqskcmAuthor
Known Participant
April 18, 2023
// Loop through all the objects in the current FLA
var doc = fl.getDocumentDOM();
var sel = doc.selection;
var numItems = sel.length;
for (var i = 0; i < numItems; i++) {
  var item = sel[i];
  if (item.itemType === "movie clip") {
    // Convert movie clip to graphic symbol
    item.convertToSymbol("graphic");
    // Access the newly converted graphic symbol
    var graphicSymbol = doc.library.findItemIndex(item.name);
    // Set the properties of the graphic symbol
    doc.library.items[graphicSymbol].setIsLooping(false); // Example property, replace with the desired property
  }
}
Multoman
Inspiring
April 18, 2023

do you mean that "setIsLooping(false)" is a property of looping a graphic symbol (Cycle, one frame, play once)?

kqskcmAuthor
Known Participant
April 18, 2023

seems to work
But the movie clip in the symbol failed to change to the graphic symbol

// Loop through all elements on the stage
var doc = fl.getDocumentDOM();
var timeline = doc.getTimeline();
for (var i = 0; i < timeline.layers.length; i++) {
  var layer = timeline.layers[i];
  for (var j = 0; j < layer.frames.length; j++) {
    var frame = layer.frames[j];
    var elements = frame.elements;
    for (var k = 0; k < elements.length; k++) {
      var element = elements[k];
      
      // Check if the element is a symbol
      if (element.elementType === "instance") {
        // Adjust properties of the symbol
        element.symbolType = "graphic";
        // Additional property adjustments can be made here
        
      }
    }
  }
}
kqskcmAuthor
Known Participant
April 18, 2023

Use jsfl to adjust movie clip properties of all objects to graphic symbols