Skip to main content
Firewood:D
Inspiring
Sep 23, 2023 10:08 AM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Sep 23, 2023 12:40 PM UTC

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

3 replies

Vladin M. Mitov
Vladin M. MitovCorrect answer
Inspiring
Sep 23, 2023 12:40 PM UTC

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.


Translate
- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Firewood:D
Inspiring
Sep 23, 2023 1:04 PM UTC

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.

Translate
kglad
Community Expert
Community Expert
Sep 23, 2023 2:53 PM UTC

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

Translate