This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
Shading is another technique that can add a lot of depth to an shape in a 3D space. Basically, you're just colorizing your shapes based on some factor like rotation or, surprise surprise, depth. Perhaps you want to give the impression of fog or night. Shading faces white or black as those faces recede into the distance can give these effects. What about shading based on a light source. Also doable... but more complex. You start getting into higher math at this point - something I've been trying to avoid so it won't be covered (...yet?). Fog, however, is fairly easy and can be beneficial if you want to prevent having to worry about objects being drawn far off in the distance.
Given any shape in your 3D scene, you have a specific coordinate telling you where that object is in relation to the view in terms of z. Using this distance, you can apply a fog of some sort by tinting a shape or face directly proportionate to that z value helping you achieve a greater sense of depth. We'll bring back our two rows of figures and add fog to them.
[ fog applied to figures in the distance ]
var tint = Math.min(z/5, 255);
this.col.setTransform({rb:tint, gb:tint, bb: tint});
Here, col, a color object for the figure is set to have a tint 1/5 the value of z (out of 255). This means that the figure will be fully white when its z is 255 x 5 or 1275. Of course the Color object, col, would need to be defined...
for (i=0; i < 8; i++){
// other actions...
attachedObj.col = new Color(attachedObj);
}
walkAround = function(){
cameraView.rotation += this._xmouse/5000;
var fmovement = 0;
if (Key.isDown(Key.UP)) fmovement += 10;
if (Key.isDown(Key.DOWN)) fmovement -= 10;
var smovement = 0;
if (Key.isDown(Key.LEFT)) smovement += 10;
if (Key.isDown(Key.RIGHT)) smovement -= 10;
cameraView.x += Math.sin(cameraView.rotation)*fmovement;
cameraView.z += Math.cos(cameraView.rotation)*fmovement;
cameraView.x += Math.sin(cameraView.rotation-Math.PI/2)*smovement;
cameraView.z += Math.cos(cameraView.rotation-Math.PI/2)*smovement;
for (var i=0; i < objectsInScene.length; i++){
objectsInScene[i].display();
}
};
theScene.onEnterFrame = walkAround;
You may feel that you have learned everything there is to know about 3D in Flash, but there is still a bit more left.
That wraps up this tutorial. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums. Your support is what keeps writing like this online! 😇
This tutorial was written by senocular, also known as Trevor McCauley. He has been one of this community's most generous teachers since the early Flash days, and he is still around: find him on senocular.com and on the forums.
:: Copyright KIRUPA 2026 //--