We’re officially starting with Chapter 3 instead of Chapters 1 or 2.
Chapter 1 is more of an overview of Robert Penner’s history and learning process.
Chapter 2 begins to teach Object Oriented Programming and some of Penner’s techniques to use OOP with AS1.
Since I am converting the AS1 classes to AS2, we can leave off that chapter. If you want an overview of OOP, there are plenty of resources out there including multiple Flash AS2 books on the subject.
Chapter 3 lays out the framework for working with Trigonometry and Coordinate Systems in Flash. Both are essential throughout the rest of the book.
I’ve broken down the AS1 code in Chapter 3 into 3 seperate AS2 classes: Degree, MathUtil, and Polar, all of which will be included in the com.robertpenner.utils namespace.
(I won’t be walking you through too much of the usage of these classes, because they are covered in depth in the actual book. My documentation will include at least one usage of each method, but beyond that you really should buy the book.)
Documentation:
com.robertpenner.utils.Degree
com.robertpenner.utils.MathUtil
com.robertpenner.utils.Polar
Source:
Penner AS2 ProFMX: Chapter 3 Classes
Click image to view demo
Below you will find the updated code for the example at the end of Chapter 5 to show you how to use the two classes from the Chapter 5 Penner AS2 post.
Add the following code on the first frame of a blank MovieClip centered on the stage.
Make sure to have another MovieClip exported for ActionScript with the linkage name of “dot” in the library to be used as the actual 3d graphic.
import com.robertpenner.display.Graphic3d; function getWallPoints (width:Number, height:Number, xDivisions:Number, yDivisions:Number):Array { var x:Number; var y:Number; var z:Number; var pts:Array = new Array(); var depth:Number = 0; for (var i:Number = 0; i <= xDivisions; i++) { for (var j:Number = 0; j <= yDivisions; j++) { x = width * (i / xDivisions - .5); y = height * (j / yDivisions - .5); z = 0; pts.push(new Graphic3d(x, y, z, this, "dot", depth++)); } } return pts; } function arrayRotateXY (particleArr:Array, angleX:Number, angleY:Number):Void { var i:Number = particleArr.length; while (i--) { particleArr[i].position.rotateXY(angleX, angleY); particleArr[i].render(); } } var wall:Array = getWallPoints (100, 100, 4, 6); this.onEnterFrame = function() { this.arrayRotateXY (wall, _ymouse/20, _xmouse/20); }