Monday, November 30th, 2009
So, I’ve got a new brief that requires me to make use of hexagons in Flash. Not a problem I said and went about making a base Polygon class, and without further ado, here it is.
It’s very simple to use, so far I’ve only made a Hexagon subclass, but I’ll make more. Nevertheless, here’s how you would use it:
{
import com.firestartermedia.lib.as3.display.shape.Hexagon;
import flash.display.Sprite;
[SWF( backgroundColor='#FFFFFF', frameRate='30', width='580', height='450' )]
public class Polygon1 extends Sprite
{
public function Polygon1()
{
var hex:Hexagon = new Hexagon();
hex.x = stage.stageWidth / 2;
hex.y = stage.stageHeight / 2;
addChild( hex );
}
}
}
And this gives you:
Or if you want to have other polygons, just do this:
{
import com.firestartermedia.lib.as3.display.shape.Hexagon;
import com.firestartermedia.lib.as3.display.shape.Polygon;
import flash.display.Sprite;
[SWF( backgroundColor='#FFFFFF', frameRate='30', width='580', height='450' )]
public class Polygon2 extends Sprite
{
public function Polygon2()
{
var hex:Hexagon = new Hexagon();
hex.x = stage.stageWidth / 2 - hex.width;
hex.y = stage.stageHeight / 2;
addChild( hex );
var oct:Polygon = new Polygon( 100, 8 );
oct.x = stage.stageWidth / 2;
oct.y = stage.stageHeight / 2;
addChild( oct );
var pen:Polygon = new Polygon();
pen.x = stage.stageWidth / 2 + pen.width;
pen.y = stage.stageHeight / 2;
addChild( pen );
}
}
}
And this produces:
The code’s all up on github, so feel free to fork and play! Tell me what you think!