0

我正在尝试编写一个与当前选定的顶点/顶点/点一起使用的 JSFL 命令,我找不到任何方法来访问当前选定的一个或多个点。

我已经搜索了 JSFL 参考,唯一处理选定顶点的方法是 moveSelectedBezierPointsBy();

4

2 回答 2

1

试图解决类似的问题我做了一些肮脏的把戏,这可能会有所帮助:

// array for some manipulations
var selPoints = new Object();

// array with all points in layer[0] and frames[0] 
var allBezierPoints = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].vertices

// read and write all points coord
for ( i in allBezierPoints ) {
    selPoints[i] = { x:allBezierPoints[i].x, y:allBezierPoints[i].y }   
}

// now dirty trick - move selected points by 1 px on X
fl.getDocumentDOM().moveSelectedBezierPointsBy({x:1, y:0});

// reseting all points
allBezierPoints = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].vertices

// compare old coord and new coord of all points
for ( i in allBezierPoints ) {
    // if coords similar, ther erase this point from array
    if ( allBezierPoints[i].x == selPoints[i].x ) delete selPoints[i];
}

// move selected points back
fl.getDocumentDOM().moveSelectedBezierPointsBy({x:-1, y:0});

// now we have array with selected points and they coordinates
for ( i in selPoints) {
    fl.trace ( "Point " + i + " X: "+selPoints[i].x +", Y: "+ selPoints[i].y)
}
于 2013-06-04T13:24:20.690 回答
0

这实际上取决于您要对顶点做什么,但这应该可以帮助您入门。

这是我过去用来从舞台上的形状中检索顶点信息的一些代码:

// Trace Vertex Information - Andrew Doll
// http://www.andrewdollanimation.com/

// Clear the output panel.
fl.outputPanel.clear();

var dom = fl.getDocumentDOM();
var tl = dom.getTimeline();
var foundMovieClips = false;
var layer;
var frame;
var element;
var vertices = [];
var movieClips = [];
var newLine = "\r\n";
var lockStatus;

// grab layers
var layers = tl.layers;

// layer loop
for (var i = 0; i < layers.length; i++)
{
    layer = layers[i];

    // Check if the layer is locked.
    lockStatus = layer.locked;
    if (lockStatus)
    {
        layer.locked = false;
    }
    // Frame loop 
    for (var j = 0; j < layer.frames.length; j++)
    {
        frame = layer.frames[j];

        // Element loop
        for (var k = 0; k < frame.elements.length; k++)
        {
            element = frame.elements[k];
            element.selected = true;

            // Only check elements that are shapes.
            if (element.elementType == 'shape')
            {
                vertices = element.vertices;
                var vertArray = [];

                // Vertice loop
                for (var l = 0; l < vertices.length; l++)
                {
                    // Push the x and y coordinates of the vertices to the vertArray.
                    vertArray.push(' x: ' + vertices[l].x + ' y: ' + vertices[l].y);
                }

                // Trace the vertex count per frame.
                fl.trace('The vertex count of frame ' + (j + 1) + ' on ' + layer.name + ' is: ' + vertices.length + newLine);

                for (var m = 0; m < vertArray.length; m++)
                {
                    // Trace the vertex locations.
                    fl.trace('Vertex ' + (m + 1) + ' on frame ' + (j + 1) + ' is located at: ' + vertArray[m]);
                }
            }
            else if (element.elementType == 'instance')
            {
                // If a movie clip is found add it to the movie clips array.
                foundMovieClips = true;
                movieClips.push(element.libraryItem.name);
            }
        }
        if (foundMovieClips)
        {
            foundMovieClips = false;
            fl.trace('LAYER:  ' + layer.name + ' FRAME:  ' + (j + 1) + ' SYMBOL:  ' + movieClips[j]);
        }
    }
}

上面的代码将遍历主时间轴的所有层上的帧,并追踪每一帧的顶点数,如果遇到影片剪辑而不是形状,它将追踪影片剪辑的名称。除了追踪顶点数之外,它还将追踪形状元素上每个顶点的 X 和 Y 坐标(如果在每一帧上找到)。

更进一步,您可以使用 JSFL 方法:vertex.setLocation()遍历顶点对象数组并将它们移动到新的 X 和 Y(如果这是您希望做的)。同样,这实际上取决于您最终要对顶点做什么,但这应该可以帮助您入门。希望这个答案对您有所帮助。

于 2013-05-03T17:31:23.740 回答