我正在尝试编写一个与当前选定的顶点/顶点点/点一起使用的JSFL命令,我找不到任何方法来访问当前选定的点或点。
我搜索了JSFL参考文献,处理选定顶点的唯一方法是moveSelectedBezierPointsBy();
答案 0 :(得分: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)
}
答案 1 :(得分: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,如果这是您想要做的。同样,它实际上取决于你最终尝试用顶点做什么,但这应该让你开始。希望您觉得这个答案很有帮助。