用 JSFL 填充图形

发布于 2024-08-21 00:46:06 字数 341 浏览 12 评论 0原文

例如,我使用 JSFL 方法在 Flsh ID 中绘制图形

// draw rectangle
doc.addNewLine({x:0, y:0}, {x:2000, y:0});
doc.addNewLine({x:2000, y:0}, {x:2000, y:500});
doc.addNewLine({x:2000, y:500}, {x:0, y:500});
doc.addNewLine({x:0, y:500}, {x:0, y:0});
// how can I fill it, because this way doesn't work
doc.setFillColor('#0000ff');

I draw figure in Flsh ID with JSFL methods, for example

// draw rectangle
doc.addNewLine({x:0, y:0}, {x:2000, y:0});
doc.addNewLine({x:2000, y:0}, {x:2000, y:500});
doc.addNewLine({x:2000, y:500}, {x:0, y:500});
doc.addNewLine({x:0, y:500}, {x:0, y:0});
// how can I fill it, because this way doesn't work
doc.setFillColor('#0000ff');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煮酒 2024-08-28 00:46:06

试试这个:

var doc = fl.getDocumentDOM();
// draw rectangle
doc.addNewLine({x:0, y:0}, {x:2000, y:0});
doc.addNewLine({x:2000, y:0}, {x:2000, y:500});
doc.addNewLine({x:2000, y:500}, {x:0, y:500});
doc.addNewLine({x:0, y:500}, {x:0, y:0});
//fill
fl.getDocumentDOM().selectAll();
fl.getDocumentDOM().union();

var fillA = fl.getDocumentDOM().getCustomFill();
fillA.style = 'radialGradient';
fl.getDocumentDOM().setCustomFill(fillA);

var fillB = fl.getDocumentDOM().getCustomFill();
fillB.style = "solid";
fillB.color = 0x0000FF;
fl.getDocumentDOM().setCustomFill(fillB);

实际上,功劳归于Christian Guirreri,而不是我。
这是完整的 jsfl 文章

Try this:

var doc = fl.getDocumentDOM();
// draw rectangle
doc.addNewLine({x:0, y:0}, {x:2000, y:0});
doc.addNewLine({x:2000, y:0}, {x:2000, y:500});
doc.addNewLine({x:2000, y:500}, {x:0, y:500});
doc.addNewLine({x:0, y:500}, {x:0, y:0});
//fill
fl.getDocumentDOM().selectAll();
fl.getDocumentDOM().union();

var fillA = fl.getDocumentDOM().getCustomFill();
fillA.style = 'radialGradient';
fl.getDocumentDOM().setCustomFill(fillA);

var fillB = fl.getDocumentDOM().getCustomFill();
fillB.style = "solid";
fillB.color = 0x0000FF;
fl.getDocumentDOM().setCustomFill(fillB);

Credits actually go to Christian Guirreri, not me.
Here is the full jsfl article.

番薯 2024-08-28 00:46:06

我发现另一种对于在舞台上填充形状很有用的方法。这包含了您的矩形形状和“#0000FF”颜色:

// Create Rectangle With Fill - Andrew Doll

var dom = fl.getDocumentDOM();
if (dom == null)
{
    alert('Please open a file.');
}
else
{
    // Declare variables.
    var tl = dom.getTimeline();
    var curLayer = tl.currentLayer;
    var curFrame = tl.currentFrame;
    var lockStatus = tl.layers[curLayer].locked;
    var myElements = tl.layers[curLayer].frames[0].elements;

    if (lockStatus)
    {
        alert('Unlock the layer.');
    }
    else
    {
        // Draw rectangle.
        dom.addNewLine({x:0, y:0}, {x:2000, y:0});
        dom.addNewLine({x:2000, y:0}, {x:2000, y:500});
        dom.addNewLine({x:2000, y:500}, {x:0, y:500});
        dom.addNewLine({x:0, y:500}, {x:0, y:0});

        // Sets the current layer as selected.
        tl.setSelectedLayers(curLayer);
        tl.setSelectedFrames(0, 0, true);

        // Checks to see if there is artwork selected.
        var mySelectedFrames = tl.getSelectedFrames();

        // Selects current frame.
        tl.setSelectedFrames(curFrame, curFrame, true);

        // Sets the fill color for the inside of the object.
        var insideContour = dom.selection[0].contours[0]; 
        var insideFill = insideContour.fill;
        insideFill.color = '#0000ff';
        dom.setFillColor('#0000ff');
        dom.selectNone();
    }
}

Another method that I have found useful for filling shapes on the stage. This incorporates your rectangle shape and the "#0000FF" color:

// Create Rectangle With Fill - Andrew Doll

var dom = fl.getDocumentDOM();
if (dom == null)
{
    alert('Please open a file.');
}
else
{
    // Declare variables.
    var tl = dom.getTimeline();
    var curLayer = tl.currentLayer;
    var curFrame = tl.currentFrame;
    var lockStatus = tl.layers[curLayer].locked;
    var myElements = tl.layers[curLayer].frames[0].elements;

    if (lockStatus)
    {
        alert('Unlock the layer.');
    }
    else
    {
        // Draw rectangle.
        dom.addNewLine({x:0, y:0}, {x:2000, y:0});
        dom.addNewLine({x:2000, y:0}, {x:2000, y:500});
        dom.addNewLine({x:2000, y:500}, {x:0, y:500});
        dom.addNewLine({x:0, y:500}, {x:0, y:0});

        // Sets the current layer as selected.
        tl.setSelectedLayers(curLayer);
        tl.setSelectedFrames(0, 0, true);

        // Checks to see if there is artwork selected.
        var mySelectedFrames = tl.getSelectedFrames();

        // Selects current frame.
        tl.setSelectedFrames(curFrame, curFrame, true);

        // Sets the fill color for the inside of the object.
        var insideContour = dom.selection[0].contours[0]; 
        var insideFill = insideContour.fill;
        insideFill.color = '#0000ff';
        dom.setFillColor('#0000ff');
        dom.selectNone();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文