Fill figure with JSFL

寵の児 提交于 2019-12-07 22:32:36

问题


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');

回答1:


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.




回答2:


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();
    }
}


来源:https://stackoverflow.com/questions/2261869/fill-figure-with-jsfl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!