Contact Me


Recent Posts


Categories


Archives


Tags

3d actionscript Actionscript 2 Actionscript 3 api APIs as2 as3 brand caching carousel channel code compress contest contract CSS Flash flv fp10 free freelance gadget gadgets gdata google JavaScript jquery mvc papervision papervision3d PHP player playlist puremvc pv3d search tube tutorial twitter video widget XML you youtube

Recent Comments

  • Ahmed: Can you put up an example?
  • Ahmed: Hmmm sorry this is a tough one but I don’t work with ASP.NET! Sorry!
  • Michael: Good example but one question… in all the slider skinning I see with Flex the thumb overruns the left...
  • venkata: Hi I am using OAuth to connect to youtube api. I got accessToken and TokenSecret for a particular user. Now...
  • Ahmed: Good old flexlib, what component are you using?

Links


Help end world hunger

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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!


2 Responses to “Did Someone Say Polygons?”

Leave a Reply

Your comment:

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Fork me on GitHub