Ahmed Nuaman


builder of internets ~ developer of dreams ~ tamer of Dachshunds

Did Someone Say Polygons?

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:

package
{
    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:

package
{
    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!

Where have comments gone?

Good question my old fruity. I'm now sticking any post discussions on Google+. Why? Well simply it's better. WordPress's comment system isn't very elegant and nor are ones like Disqus or Livefyre, so to save hassle I've just shipped them off to a social network, like a real boss.

Search

My social skills

Latest blog posts

  • Loading posts...

Subscribe in a reader

Latest tweets

  • Loading tweets...