Skip to main content
Firewood:D
Inspiring
September 23, 2023
Answered

Assuming that the drawing object is a group, how to add a stroke to it using jsfl?

  • September 23, 2023
  • 1 reply
  • 505 views

I have some confusion. When the object I select is a drawing object or shape, I can use the following code to add a stroke to it.

fl.getDocumentDOM().selection[0].x += 0;
fl.getDocumentDOM().setStrokeSize(10);

This code cannot take effect on the selected group or symbol.

Using the history function I get code like this:

an.getDocumentDOM().setStroke('#000000', 10, 'solid');

Repeated operations found that this code only takes effect on the drawing object union.

Back to my question:
If the selected object is a group or symbol, the following code cannot stroke it.

customStrokeWidth = 10; 
if (customStrokeWidth) {
  var doc = fl.getDocumentDOM();
  var selection = doc.selection[0];
  myStroke(selection, customStrokeWidth);
}
function  myStroke(element, strokeWidth) {
  if (element.elementType === "group") {
    var elements = element.getElements();
    for (var i = 0; i < elements.length; i++) {
      var nestedElement = elements[i];
      myStroke(nestedElement, strokeWidth);
    }
  } else {
    doc.selection = [element];
    doc.setStrokeSize(strokeWidth);
  }
}​

Did I miss something?

This topic has been closed for replies.
Correct answer Vladin M. Mitov

Yes, the setStrokeSize() method sets the stroke size of the selected object,
but only if the object is either a raw shape or a union.

Symbols, on the other hand, cannot have their strokes directly modified since they are not raw shapes. To achieve this, you must enter to the symbol's timeline via the method enterEditMode() and iterate through its objects, adjusting their stroke sizes individually.

Similarly, modifying the stroke of a group is not possible because groups are not raw shapes or unions.
Unfortunately, you cannot access their timeline for adjustments since it does not exist for groups.


1 reply

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
September 23, 2023

Yes, the setStrokeSize() method sets the stroke size of the selected object,
but only if the object is either a raw shape or a union.

Symbols, on the other hand, cannot have their strokes directly modified since they are not raw shapes. To achieve this, you must enter to the symbol's timeline via the method enterEditMode() and iterate through its objects, adjusting their stroke sizes individually.

Similarly, modifying the stroke of a group is not possible because groups are not raw shapes or unions.
Unfortunately, you cannot access their timeline for adjustments since it does not exist for groups.


- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Firewood:D
Inspiring
September 23, 2023

I see, this is really a headache. In my recent project, I needed to add strokes to a lot of materials without strokes, so I thought of this.

kglad
Community Expert
Community Expert
September 23, 2023

it's just more coding and if you really have a lot of things to edit can still be very efficient.