Start by downloading the Graffiti Library and extract the contents of the zip file.

Browse to the 'source' directory and copy the 'com' folder and all it's contents to your project directory.

Create a new Flash CS3 (ActionScript 3) document and save it to your project directory.

If your FLA document and the 'com' folder are NOT in the same directory, you will need to add the location of the 'com' folder to the classpath.
You need to import a few classes before we can use the Graffiti Library.
import com.nocircleno.graffiti.GraffitiCanvas; import com.nocircleno.graffiti.tools.Brush; import com.nocircleno.graffiti.tools.BrushType; import com.nocircleno.graffiti.tools.Line; import com.nocircleno.graffiti.tools.LineType; import com.nocircleno.graffiti.tools.Shape; import com.nocircleno.graffiti.tools.ShapeType;
The GraffitiCanvas Class is the main component of the Graffiti Library. The GraffitiCanvas Class extends the Sprite Class so it can be added anywhere in the Display List.
There are 5 optional parameters we can set when creating a new instance of the GraffitiCanvas Class.
// create a canvas with a width and height that matches the stage dimensions var canvas:GraffitiCanvas = new GraffitiCanvas(stage.stageWidth, stage.stageHeight); addChild(canvas);
When we create a new instance of the GraffitiCanvas, a Brush instance is created and assigned as the active tool automatically.
// create a diamond brush of size 8 and color red var diamondBrush:Brush = new Brush(8, 0xFF0000, BrushType.DIAMOND);
// Set canvas active tool to use the diamond brush we just created. canvas.activeTool = diamondBrush;
// create a dotted line of size 4 and grey var dottedLine:Line = new Line(4, 0xBBBBBB, LineType.DOTTED); // Set canvas active tool to use the dotted line we just created. canvas.activeTool = dottedLine;
// create a rectangle shape tool with grey stroke and a red fill. var rectangleShape:Shape = new Shape(2, 0xBBBBBB, 0xFF0000, ShapeType.RECTANGLE); // Set canvas active tool to use the rectangle shape tool we just created. canvas.activeTool = rectangleShape;
// create a dotted line of size 4 and grey var dottedLine:Line = new Line(4, 0xBBBBBB, LineType.DOTTED); // Set canvas active tool to use the dotted line we just created. canvas.activeTool = dottedLine; // change dottedLine properties dottedLine.lineWidth = 8; dottedLine.color = 0xFF0000;
If you change a property of a Tool that is currently assigned to the Canvas then the Canvas is automatically updated.
In a later tutorial I'll go over some more advanced features and techniques.