package { import flash.display.Graphics; import flash.display.Sprite; //Class to create a simple 3D object public class ModelSprite extends Sprite { //These var's aren't needed after addChild() is called, //but are useful if you want to experiment after the //scene is created private var floor:Sprite; private var wall:Sprite; private var wall2:Sprite; private var wall3:Sprite; private var ceiling:Sprite; private const WALL_HEIGHT:int = 60; //150; private const WALL_LENGTH:int = 100; private const CEILING_WIDTH:int = 25; private const WALL_X:int = 100; private const WALL_Y:int = 10; private const FLOOR_SIZE:int = 150; // center the object on the registration point (0,0) private const ORIGIN_X:int = -FLOOR_SIZE/2; private const ORIGIN_Y:int = -FLOOR_SIZE/2; //Create a simple 3D object with a floor, some walls, and a ceiling public function ModelSprite():void { super(); create_Floor(); create_Wall2(); create_Wall3(); create_Wall(); create_Ceiling(); //Move the objects close to the viewer in the local 3D space //Affects zooming floor.z -=1; wall3.z -=1; wall2.z -=1; wall.z -=1; ceiling.z -=1; } //First wall is a flat rectangle, rotated on the Y axis to //"stand it up" private function create_Wall():void { wall = new Sprite(); wall.x = ORIGIN_X + WALL_X; wall.y = ORIGIN_Y + WALL_Y; wall.graphics.beginFill(0xFCB2FF, 1.0); wall.graphics.drawRect(0,0,WALL_HEIGHT,WALL_LENGTH); wall.graphics.endFill(); wall.rotationY = 90; addChild(wall); } //Second wall is a flat rectangle, rotated on the Y axis to //"stand it up" private function create_Wall2():void { wall2 = new Sprite();// container wall2.x = ORIGIN_X + WALL_X + CEILING_WIDTH; wall2.y = ORIGIN_Y + WALL_Y; //wall2.graphics.beginFill(0xFCB2FF, 1.0); //wall2.graphics.beginFill(0xC8BFFF, 1.0); wall2.graphics.beginFill(0xE8D8AE, 1.0); wall2.graphics.drawRect(0,0,WALL_HEIGHT,WALL_LENGTH); wall2.graphics.endFill(); wall2.rotationY = 90; addChild(wall2); } //Third wall is a flat rectangle, at 90 degrees to the other two walls, //connecting them. It is rotated on the X axis instead of the Y axis. private function create_Wall3():void { wall3 = new Sprite();// container wall3.x = ORIGIN_X + WALL_X; wall3.y = ORIGIN_Y + WALL_Y; wall3.graphics.beginFill(0xC8BFFF, 1.0); wall3.graphics.drawRect(0,0,CEILING_WIDTH,WALL_HEIGHT); wall3.graphics.endFill(); wall3.rotationX = -90; addChild(wall3); } //The ceiling is just a flat rectangle, except closer to the //viewer so it's on "top" (z value). private function create_Ceiling():void { ceiling = new Sprite();// container ceiling.x = ORIGIN_X + WALL_X; ceiling.y = ORIGIN_Y + WALL_Y; ceiling.graphics.beginFill(0xBFFFDF, 1.0); ceiling.graphics.drawRect(0,0,CEILING_WIDTH,WALL_LENGTH); ceiling.graphics.endFill(); ceiling.z = -WALL_HEIGHT; addChild(ceiling); } //The floor is just a flat rectangle private function create_Floor():void { floor = new Sprite();// container //Draw flat plane floor.graphics.beginFill(0x908072, 1.0); floor.graphics.drawRect(ORIGIN_X,ORIGIN_Y, 150, 150); floor.graphics.endFill(); addChild(floor); } } }