Copy link to clipboard
Copied
I would like to know if it is possible to create an element from scratch by recreating all of its child objects. For exemple :
myData : shapeObject:{property1:value1,property2:value2,...also containing other object like edges Object etc...}
frames[n].elements=[shapeObject]
Think of it like an export out of Animate of a shapeObject and then trying to recreate it based on the object data.
Copy link to clipboard
Copied
Yes, it is possible. Here is an example how to create a shape by given simple "description":
// Your example object description:
var myData = {
stroke:{ color:"#CC0000", thickness:10 },
fill:{ color:"#FF0000" },
vertices:[ {x:10, y:10}, {x:100, y:100}, {x:10, y:100} ]
};
function drawObject( doc, data ){
var stroke = doc.getCustomStroke( "toolbar" );
var fill = doc.getCustomFill("toolbar" );
stroke.color = data.stroke.color;
stroke.thickness = data.stroke.thickness;
fill.color = data.fill.color;
doc.setCustomStroke( stroke );
doc.setCustomFill( fill );
var path = fl.drawingLayer.newPath();
for( var i = 0; i < data.vertices.length; i++ ){
var vertex = data.vertices[ i ];
path.addPoint( vertex.x, vertex.y );
}
path.close();
path.makeShape( false, false );
doc.selectAll();
doc.convertToSymbol( 'graphic', '', 'center' );
}
drawObject( fl.getDocumentDOM(), myData );
Copy link to clipboard
Copied