Home > FlashDevelop > Snippets : shapes

Snippets : shapes

November 29th, 2010 Leave a comment Go to comments

Now and then I have a need to quickly add simple shape to my visual object. In most cases for fast and rough debugging. Sometimes for prototyping application if I still don’t have visuals, and sometimes… well I need a shape! :)

Here are couple of snippets to add quick shape to your DisplayObject.

 

#shape-rectangle

var $$(shapeVar=rectangle):Shape = new Shape();
$$(shapeVar).graphics.lineStyle($$(lineThickness=0.1,1,2,3,4,5,10), $$(lineColor=0xFF0000,0×000000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.beginFill($$(fillColor=0x0000FF,0×000000,0xFF0000,0x00FF00,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.drawRect($$(x=0), $$(y=0), $$(width=100), $$(height=100));
$$(shapeVar).graphics.endFill();
this.addChild($$(shapeVar));

#shape-roundRectangle

var $$(shapeVar=roundRectangle):Shape = new Shape();
$$(shapeVar).graphics.lineStyle($$(lineThickness=0.1,1,2,3,4,5,10), $$(lineColor=0xFF0000,0×000000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.beginFill($$(fillColor=0x0000FF,0×000000,0xFF0000,0x00FF00,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.drawRoundRect($$(x=0), $$(y=0), $$(width=100), $$(height=100), $$(ellipseWidth=20));
$$(shapeVar).graphics.endFill();
this.addChild($$(shapeVar));

#shape-circle

var $$(shapeVar=circle):Shape = new Shape();
$$(shapeVar).graphics.lineStyle($$(lineThickness=0.1,1,2,3,4,5,10), $$(lineColor=0xFF0000,0×000000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.beginFill($$(fillColor=0x0000FF,0×000000,0xFF0000,0x00FF00,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.drawCircle($$(x=0), $$(y=0), $$(radius=100));
$$(shapeVar).graphics.endFill();
this.addChild($$(shapeVar));

#shape-ellipse

var $$(shapeVar=ellipse):Shape = new Shape();
$$(shapeVar).graphics.lineStyle($$(lineThickness=0.1,1,2,3,4,5,10), $$(lineColor=0xFF0000,0×000000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.beginFill($$(fillColor=0x0000FF,0×000000,0xFF0000,0x00FF00,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.drawEllipse($$(x=0), $$(y=0), $$(width=100), $$(height=80));
$$(shapeVar).graphics.endFill();
this.addChild($$(shapeVar));

#shape-path

This one is hard to modify and use just by editing snippet parameters, but for quick lines or not standard shape it’s nice starting point as example.

var $$(shapeVar=path):Shape = new Shape();
$$(shapeVar).graphics.lineStyle($$(lineThickness=0.1,1,2,3,4,5,10), $$(lineColor=0xFF0000,0x000000,0x00FF00,0x0000FF,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.beginFill($$(fillColor=0x0000FF,0x000000,0xFF0000,0x00FF00,0xFFFF00,0xFF00FF,0x00FFFF,0xFFFFFF));
$$(shapeVar).graphics.drawPath(
new <int>[
$$(command1=GraphicsPathCommand.MOVE_TO,GraphicsPathCommand.LINE_TO,GraphicsPathCommand.CURVE_TO),
$$(command2=GraphicsPathCommand.LINE_TO,GraphicsPathCommand.MOVE_TO,GraphicsPathCommand.CURVE_TO),
$$(command3=GraphicsPathCommand.LINE_TO,GraphicsPathCommand.MOVE_TO,GraphicsPathCommand.CURVE_TO),
$$(command4=GraphicsPathCommand.CURVE_TO,GraphicsPathCommand.LINE_TO,GraphicsPathCommand.MOVE_TO),
$$(command5=GraphicsPathCommand.LINE_TO,GraphicsPathCommand.MOVE_TO,GraphicsPathCommand.CURVE_TO)
],
new <Number>[
$$(point1x=50), $$(point1y=0),
$$(point2x=100), $$(point2y=50),
$$(point3x=80), $$(point3y=150),
$$(point4x=50), $$(point4y=0), $$(point5x=20), $$(point5y=150),
$$(point6x=0), $$(point6y=50)
]);
$$(shapeVar).graphics.endFill();
this.addChild($$(shapeVar));

Categories: FlashDevelop Tags: ,
  1. Koala
    April 20th, 2011 at 01:01 | #1

    thank you!
    these snippets are so great!

  1. No trackbacks yet.

MindScriptAct is Stephen Fry proof thanks to caching by WP Super Cache