Adobe 65011817 Extended User Guide - Page 303
Defining the shape
UPC - 883919157368
View all Adobe 65011817 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 303 highlights
Last updated 12/8/2009 EXTENDING FIREWORKS 299 Auto Shapes Defining the shape The following code creates the initial shape, a rectangle (a more concise way of creating an initial shape follows this example): function InsertSmartShapeAt() { smartShape.elem.elements[0] = new Path; smartShape.elem.elements[0].contours[0] = new Contour; smartShape.elem.elements[0].contours[0].nodes[0] = new ContourNode; smartShape.elem.elements[0].contours[0].nodes[0].predX = 0; smartShape.elem.elements[0].contours[0].nodes[0].predY = 0; smartShape.elem.elements[0].contours[0].nodes[0].x = 0; smartShape.elem.elements[0].contours[0].nodes[0].y = 0; smartShape.elem.elements[0].contours[0].nodes[0].succX = 0; smartShape.elem.elements[0].contours[0].nodes[0].succY = 0; smartShape.elem.elements[0].contours[0].nodes[1] = new ContourNode; smartShape.elem.elements[0].contours[0].nodes[1].predX = 200; smartShape.elem.elements[0].contours[0].nodes[1].predY = 0; smartShape.elem.elements[0].contours[0].nodes[1].x = 200; smartShape.elem.elements[0].contours[0].nodes[1].y = 0; smartShape.elem.elements[0].contours[0].nodes[1].succX = 200; smartShape.elem.elements[0].contours[0].nodes[1].succY = 0; smartShape.elem.elements[0].contours[0].nodes[2] = new ContourNode; smartShape.elem.elements[0].contours[0].nodes[2].predX = 200; smartShape.elem.elements[0].contours[0].nodes[2].predY = 125; smartShape.elem.elements[0].contours[0].nodes[2].x = 200; smartShape.elem.elements[0].contours[0].nodes[2].y = 125; smartShape.elem.elements[0].contours[0].nodes[2].succX = 200; smartShape.elem.elements[0].contours[0].nodes[2].succY = 125; smartShape.elem.elements[0].contours[0].nodes[3] = new ContourNode; smartShape.elem.elements[0].contours[0].nodes[3].predX = 0; smartShape.elem.elements[0].contours[0].nodes[3].predY = 125; smartShape.elem.elements[0].contours[0].nodes[3].x = 0; smartShape.elem.elements[0].contours[0].nodes[3].y = 125; smartShape.elem.elements[0].contours[0].nodes[3].succX = 0; smartShape.elem.elements[0].contours[0].nodes[3].succY = 125; smartShape.elem.elements[0].contours[0].isClosed = true; } The Auto Shape is an array of ContourNode objects (see "ContourNode object" on page 239). You can write a "helper" function to simplify the code and assign ContourNode properties, as shown in the following example: function addPathPoint(contour, i, x, y) { var theNodes = contour.nodes; // Increase the length to add a new point if (i > 0) theNodes.length++; // get the new point var node = theNodes[theNodes.length - 1]; // Set the new point's values node.x = node.predX = node.succX = x; node.y = node.predY = node.succY = y; }