Overview
These methods are implemented via the graphics property (an instance of the Graphics class) of the following objects.
Shape | Shape -> DisplayObject -> EventDispatcher -> Object
|
Sprite | Sprite -> DisplayObjectContainer -> InteractiveObject -> DisplayObject -> EventDispatcher -> Object
|
MovieClip | MovieClip -> Sprite -> ...
|
public function lineStyle(thickness:Number, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):voidlineStyle is used to draw lines and borders around boxes. If it is not set, then nothing will be drawn.
thickness | The thickness of the line in points (points are not defined) |
pixelHinting | Apparently, when true, this makes lines an exact number of pixels wide and causes them to align to the grid. The help on this is totally obscure. |
scaleMode | This controls what is seen when objects are scaled. Setting this to NONE allows you to resize movies without the line widths changing. While this seems desirable, don't do it ... when you resize a running Flash movie you will want the line widths to change so that things look ok. (This is important.) |
joints | When 2 lines overlap, Flash tries to make the joint look pretty (how sweet). As a result, joints always look sloppy. The default is ROUND ... which I really hate. MITER looks better, but leaves little pieces that really detract from a clean design. |
Drawing Boxes
import flash.display.*; import flash.events.*; var box : Sprite = new Sprite(); var canvas : Graphics; canvas = box.graphics; canvas.beginFill( 0xFF0000 ) ; // red canvas.lineStyle(1, 0x000000, 1, true, LineScaleMode.NORMAL, CapsStyle.SQUARE, JointStyle.MITER); canvas.drawRect(1, 1, 100, 200); canvas.endFill(); stage.addChild(box); trace(box.width, box.height); // shows: 101 201
The Problem
Size | Border | height | width | Comment |
---|---|---|---|---|
100 x 100 | 0 | 100.2 | 100.2 | This has a thin black line around the box and a second thin line the same color as the border color outside the black line |
100 x 100 | 1 | 101.0 | 101.0 | No extra black line |
100 x 100 | 5 | 105.0 | 105.0 | No extra black line |
canvas.lineStyle(5, 0x000000, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE, JointStyle.MITER); canvas.moveTo(0,0); canvas.lineTo(100,0); trace(box.width, box.height); // shows: 100 5It would make sense if a
At any rate, the only way I've found to draw a box without a visible border is to
canvas.beginFill( 0xFF0000 ) ; // red canvas.lineStyle(1, 0xFF0000, 1, true, LineScaleMode.NORMAL, CapsStyle.SQUARE, JointStyle.MITER); canvas.drawRect(1, 1, 99, 199); canvas.endFill(); trace(box.width, box.height); // shows: 100 200In my opinion, Adobe should have included this information with the drawRect documentation.
Placing Objects
For the stage, (0,0) is the upper left corner - in the IDE, this is the upper left corner of the white area - only the white area is displayed when the movie (form) is rendered.
For objects (MovieClips) drawn in the IDE, (0,0) is indicated by the plus sign. To change the location of the plus sign, open the MovieClip in design mode and reposition the sub-components as appropriate.
New Drawing Classes
Class | Description |
---|---|
TmcPen | Provides a separate property for each parameter.
Applications can create a number of TmcPen objects and select them as appropriate. |
TmcRect | Automatically assumes that the border has zero width.
If the Pen property is not null, then create a border with it. Otherwise, do not create a border. |