// PolyLine Tool for Macromedia Flash MX2004 // // (C) 2003 bswan // function configureTool(){ var thisTool = fl.tools.activeTool; thisTool.setIcon("PolyLine.png"); thisTool.setMenuString("PolyLine Tool"); thisTool.setToolName("PolyLine Tool"); thisTool.setToolTip("PolyLine Tool"); thisTool.setOptionsFile("PolyLine.xml"); } function activate(){ thisTool = fl.tools.activeTool; thisDoc = fl.getDocumentDOM(); fillShape = thisTool.fillShape; // connect last point with first and fill the shape closeShape = thisTool.closeShape; // connect last point with first, but do not fill the shape points = new Array(); // here all the points dweling toolIsActive = false; // since tool is working not only while mouse is down - here's it's state } function notifySettingsChanged(){ fillShape = thisTool.fillShape; closeShape = thisTool.closeShape; } function mouseDown(){ // if tool already working: if (toolIsActive){ // get last fixed point: var lastNum = points.length-1; var lastPoint = points[lastNum]; // check if current point equal to first and closeShape or fillShape flags is set: if ((closeShape || fillShape) && (currPoint.x==startPoint.x && currPoint.y==startPoint.y)){ finishDraw(); // else just add current point into array and draw new line: } else { points.push(currPoint); thisDoc.addNewLine(lastPoint, currPoint); } // else if it is first mouseDown - activate tool: } else { fl.drawingLayer.beginDraw(); toolIsActive=true; points = new Array(); // renew array! startPoint = fl.tools.penDownLoc; // store firts point transformPoint(startPoint, thisDoc.viewMatrix); startPoint = fl.tools.snapPoint(startPoint); points.push(startPoint); // and add it to array } } function mouseMove(){ // if tool is active =) if (toolIsActive){ currPoint = fl.tools.penLoc; // get current point transformPoint(currPoint, thisDoc.viewMatrix); currPoint = fl.tools.snapPoint(currPoint); currPoint = fl.tools.constrainPoint(points[points.length-1], currPoint); fl.drawingLayer.beginFrame(); fl.drawingLayer.moveTo(points[points.length-1].x, points[points.length-1].y); // draw temporary new line fl.drawingLayer.lineTo(currPoint.x, currPoint.y); fl.drawingLayer.endFrame(); } } function keyDown(){ // if ESC is pressed and tool is active: if(fl.tools.getKeyDown()==27 && toolIsActive){ finishDraw(); } } function finishDraw(){ fl.drawingLayer.endDraw(); toolIsActive=false; // if fillShape flag is set - redraw all lines as closed Path: if (fillShape){ poly_path = fl.drawingLayer.newPath(); for (var i = 0; i < points.length; i++) { poly_path.addPoint(points[i].x, points[i].y); } poly_path.close(); poly_path.makeShape(); // else if closeShape flag is set - just add line between last and first points: } else if(closeShape){ thisDoc.addNewLine(startPoint, points[points.length-1]); } } // ----------------------------------- function transformPoint( pt, mat ) { var x = pt.x * mat.a + pt.y * mat.c + mat.tx; var y = pt.x * mat.b + pt.y * mat.d + mat.ty; pt.x = x; pt.y = y; }