 # Rotation around a point

The balloons in a cube shape…I’m working through this tutorial and having a little difficulty getting the thing to work. I’ve corrected a couple of things that I think were making it fail (marked in my code below), and the script now grabs my balls (f’narr f’narr) and arranges them into the correct cube shape, but rotation is still just beyond my grasp. I have 8 instances of redballoon (named redballoon0 to redballoon7) on the first frame on the main timeline, with this script in the actions layer above it…

``````this.createEmptyMovieClip("theScene", 1);
theScene._x = 150;
theScene._y = 150;
focalLength = 300;
make3DPoint = function(x,y,z){
var point = new Object();
point.x = x;
point.y = y;
point.z = z;
return point;
};
make2DPoint = function(x,y, depth, scaleFactor){
var point = new Object();
point.x = x;
point.y = y;
point.depth = depth;
point.scaleFactor = scaleFactor;
return point;
};
Transform3DPointsTo2DPoints = function(points, axisRotations){
var TransformedPointsArray = [];
var sx = Math.sin(axisRotations.x);
var cx = Math.cos(axisRotations.x);
var sy = Math.sin(axisRotations.y);
var cy = Math.cos(axisRotations.y);
var sz = Math.sin(axisRotations.z);
var cz = Math.cos(axisRotations.z);
var x,y,z, xy,xz, yx,yz, zx,zy, scaleFactor;
var i = points.length;
while (i--){
x = points*.x;
y = points*.y;
z = points*.z;
// rotation around x
xy = cx*y - sx*z;
xz = sx*y + cx*z;
// rotation around y
yz = cy*xz - sy*x;
yx = sy*xz + cy*x;
// rotation around z
zx = cz*yx - sz*xy;
zy = sz*yx + cz*xy;

scaleFactor = focalLength/(focalLength + yz);
x = zx*scaleFactor;
y = zy*scaleFactor;
z = yz;
TransformedPointsArray* = make2DPoint(x, y, -z, scaleFactor);
}
return TransformedPointsArray;
};
pointsArray = [
make3DPoint(-50,-50,-50),
make3DPoint(50,-50,-50),
make3DPoint(50,-50,50),
make3DPoint(-50,-50,50),
make3DPoint(-50,50,-50),
make3DPoint(50,50,-50),
make3DPoint(50,50,50),
make3DPoint(-50,50,50)
];
for (i=0; i < pointsArray.length; i++){
attachedObj = theScene.attachMovie("redballoon", "redballoon"+i, i);
}
cubeAxisRotations = make3DPoint(0,0,0);
rotateCube = function(){
cubeAxisRotations.y -= this._xmouse/3000;
cubeAxisRotations.x += this._ymouse/3000;
var screenPoints = Transform3DPointsTo2DPoints(pointsArray, cubeAxisRotations);
for (i=0; i < pointsArray.length; i++){
currBalloon = this["redballoon"+i];
// the line above changed from:  currBalloon = this["balloon"+i];
currBalloon._x = screenPoints*.x;
currBalloon._y = screenPoints*.y;
currBalloon._xscale = currBalloon._yscale = 100 * screenPoints*.scaleRatio;
currBalloon.swapDepths(screenPoints*.depth);
}
};
theScene.onEnterFrame = rotateCube();
// the line above changed from:  theScene.onEnterFrame = rotateCube;
``````

Can anyone tell me what I’m doing wrong?