The Custom HexCylinder Class

The class HexCylinder uses the simple 3d mechanism from our tutorial Simple 3D Drawing in Flash CS3 . If you look at the Simple 3D tutorial and compare it with the code in HexCylinder.as, you will see the same basic functions. These functions are: setVertices, setFaces, and renderView. In the HexCylinder class, the vertices and the faces correspond to a hexagonal cylinder. (You will find HexCylinder.as file and all other files related to this tutorial in the zip package tween3d.zip linked below.)

The HexCylinder class extends the Sprite class. It has the following public methods and properties which we have seen in action on the previous page.

Public Properties

  • instance.curTheta:Number  The property represents the horizontal angular displacement of the observer, in degrees. (In other words, the horizontal view angle.) After changing the property, renderView method should be called to reflect the change.
     
  • instance.curPhi:Number  The property represents the vertical angular displacement of the observer, in degrees. (In other words, the vertical view angle.) After changing the property, renderView method should be called to reflect the change.

Public Methods

  • The constructor evoked with the key word 'new': new HexCylinder(r:Number,h:Number)  The class constructor takes two parameters: the radius and the height of the cylinder. The cylinder is drawn in such a way that the registration point of each instance falls in the upper left corner.
     
  • instance.renderView(t:Number,p:Number):void  The methods draws the view of the cylinder corresponding to the horizontal view angle t, in degrees, and the vertical view angle, p, in degrees.
     
  • instance.setFacesColors(a:Array):void  The method takes an array of eight colors (in their hexadecimal representation) as a parameter and redraws the cylinder in a new coloring scheme. Dafaults: Eight rather ugly colors.
     
  • instance.setBorderColorAndThick(c:Number,t:Number):void  The method takes a color (in its hexadecimal representation) as the first parameter. The color corresponds to the color of the cylinder's outline. The second parameter corresponds to the thickness of the line of the outline. The method redraws the cylinder in a new coloring scheme. Defaults: 0xCC0000, 1.
     
  • instance.setOpacity(o:Number):void  The method sets the opacity of the faces to 'o' and redraws the cylinder. Default: 0.8.
     

Your can easily modify the class to draw other solids than a hexagonal cylinder by changing the protected methods setVertices and setFaces to reflect a different solid.

Download

  • Download all 'fla', and 'as' files corresponding to this tutorial: tween3d.zip

Back to Advanced Tutorials              Back to Flash and Math Home

The site www.flashandmath.com is maintained by Doug Ensley (doug@flashandmath.com) and Barbara Kaskosz (barbara@flashandmath.com).
It has been developed with partial funding from the National Science Foundation and the Mathematical Association of America.