In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Minecraft Player Alternativa3d 7

Code Created by David E Jones
See http://davidejones.com for my work
/**
 * Copyright davidejones ( http://wonderfl.net/user/davidejones )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oo3p
 */

// Code Created by David E Jones
// See http://davidejones.com for my work

package {
    
    import alternativ7.engine3d.core.Camera3D;
    import alternativ7.engine3d.core.Object3DContainer;
    import alternativ7.engine3d.containers.*;
    import alternativ7.engine3d.controllers.SimpleObjectController;
    import alternativ7.engine3d.core.View;
    import alternativ7.engine3d.materials.FillMaterial;
    import alternativ7.engine3d.materials.TextureMaterial;
    import alternativ7.engine3d.primitives.Box;
    import alternativ7.engine3d.core.Debug;
    import alternativ7.engine3d.core.MipMapping;
    import alternativ7.engine3d.core.Sorting;
    import alternativ7.engine3d.lights.DirectionalLight;
    import alternativ7.engine3d.materials.VertexLightMaterial;
    
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.display.BitmapData;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;
    
    import com.bit101.components.CheckBox;
    import com.bit101.components.VBox;
    import com.bit101.components.Label;
    
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    
    [SWF(backgroundColor="#000000", frameRate="30", width="560", height="340")]
    
    public class Character extends Sprite 
    {
        private var player:Object3DContainer = new Object3DContainer();
        private var container:ConflictContainer = new ConflictContainer();
        private var camera:Camera3D;
        private var controller:SimpleObjectController;
        private var headml:Object;
        private var headEml:Object;
        private var bodyml:Object;
        private var armRml:Object;
        private var armLml:Object;
        private var legRml:Object;
        private var legLml:Object;
        private var directionalLight:DirectionalLight;
        
        private var drawSmooth:Boolean = true;
        
        private var ui:Sprite;
        private var loader:Loader;
        private var bd:BitmapData;
        
        private var head:Box;
        private var headE:Box;
        private var body:Box;
        private var legL:Box;
        private var legR:Box;
        private var armL:Box;
        private var armR:Box;
        
        public function Character() 
        {
            //stage settings
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.HIGH;
            
            //container settings
            container.resolveByAABB=true;
            container.resolveByOOBB=true;
                        
            // Camera and view
            camera = new Camera3D();
            camera.view = new View(stage.stageWidth, stage.stageHeight);
            addChild(camera.view);
            addChild(camera.diagram);
            
            // Lighting            
            directionalLight = new DirectionalLight(0xFFFFFF);
            directionalLight.x = 0;
            directionalLight.z = 20;
            directionalLight.y = 20;
            //directionalLight.lookAt(0, 0, 0);
            directionalLight.rotationX = -90*Math.PI/180;
            directionalLight.rotationZ = 180*Math.PI/180;
            container.addChild(directionalLight);
            
            // Initial position
            camera.rotationX = -1.989675521850586;
            camera.rotationY = -1.365318347268385e-8;
            camera.rotationZ = -3.071779489517212;
            camera.y = 47.222782135009766;
            camera.z = 20.583066940307617;
            camera.x = -2.5103461742401123;
            container.addChild(camera);
            
            // Camera controller
            controller = new SimpleObjectController(stage, camera, 200, 3);    

            loader = new Loader();
            loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/a/ab/ab5a/ab5ad207b422120752b5c28b87d29063553a4a67"), new LoaderContext(true));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
            
            // Listeners
            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
            stage.addEventListener(Event.RESIZE, onResize);
            
            // Add player to the container
            container.addChild(player);
            
            // Initial Render
            camera.render();
            
            setupUI();
        }
        
        private function loaded(e:Event):void
        {
            bd = Bitmap(loader.content).bitmapData;
            createPlayerMaterials(bd);
            start();
        }
        
        private function start():void
        {                         
            // Create Head
            head = new Box(8, 8, 8, 1, 1, 1, false, false, headml.left, headml.right, headml.back, headml.front, headml.bottom, headml.top);
            head.z = 8;
            head.sorting = Sorting.DYNAMIC_BSP;
            head.calculateVerticesNormals(true, 0.01);
            
            // Create Head Outer Box
            headE = new Box(8.9, 8.9, 8.9, 1, 1, 1, false, false, headEml.left, headEml.right, headEml.back, headEml.front, headEml.bottom, headEml.top);
            headE.z = 8;
            headE.sorting = Sorting.DYNAMIC_BSP;
            headE.calculateVerticesNormals(true, 0.01);
            
            // Create Body
            body = new Box(8, 4, 12, 1, 1, 1, false, false, bodyml.left, bodyml.right, bodyml.back, bodyml.front, bodyml.bottom, bodyml.top);
            body.z = -2;
            body.calculateVerticesNormals(true, 0.01);
            
            // Create Left Leg
            legL = new Box(4, 4, 12, 1, 1, 1, false, false, legLml.left, legLml.right, legLml.back, legLml.front, legLml.bottom, legLml.top);
            legL.z = -14;
            legL.x = 2;
            legL.calculateVerticesNormals(true, 0.01);
            
            // Create Right Leg
            legR = new Box(4, 4, 12, 1, 1, 1, false, false, legRml.left, legRml.right, legRml.back, legRml.front, legRml.bottom, legRml.top);
            legR.z = -14;
            legR.x = -2;
            legR.calculateVerticesNormals(true, 0.01);
            
            // Create Left Arm
            armL = new Box(4, 4, 12, 1, 1, 1, false, false, armLml.left, armLml.right, armLml.back, armLml.front, armLml.bottom, armLml.top);
            armL.z = -2;
            armL.x = 6;
            armL.calculateVerticesNormals(true, 0.01);
            
            // Create Right Arm
            armR = new Box(4, 4, 12, 1, 1, 1, false, false, armRml.left, armRml.right, armRml.back, armRml.front, armRml.bottom, armRml.top);
            armR.z = -2;
            armR.x = -6;
            armR.calculateVerticesNormals(true, 0.01);
            
            // Add all body parts to the player object
            player.addChild(head);
            player.addChild(headE);
            player.addChild(body);
            player.addChild(legL);
            player.addChild(legR);
            player.addChild(armL);
            player.addChild(armR);
        }
        
        private function onEnterFrame(e:Event):void {
            // Width and height of view
            camera.view.width = stage.stageWidth;
            camera.view.height = stage.stageHeight;
            
            // Rotation
            player.rotationZ -= 0.05;
            
            // controller
            controller.update();
                        
            // Render
            camera.render();
        }
        
        private function createPlayerLightMaterials(src:BitmapData):void
        {
            // Texture material settings,
            // you should probably extend TextureMaterial Rather than do this but meh
            var repeat:Boolean = false;
            var smooth:Boolean = false;
            var mipMapping:int = 0;
            var resolution:Number = 1;
            
            // HEAD texture materials
            var front_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var back_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(24, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var left_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(16, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var right_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(0, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var top_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            var bottom_head:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(16, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            headml = new Object();
            headml.front = front_head;
            headml.back = back_head;
            headml.left = left_head;
            headml.right = right_head;
            headml.top = top_head;
            headml.bottom = bottom_head;
            
            // HEADE texture materials
            var front_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(40, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var back_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(56, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var left_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var right_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(32, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var top_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(40, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            var bottom_heade:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            headEml = new Object();
            headEml.front = front_heade;
            headEml.back = back_heade;
            headEml.left = left_heade;
            headEml.right = right_heade;
            headEml.top = top_heade;
            headEml.bottom = bottom_heade;
            
            // BODY texture materials
            var front_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(20, 20), 8, 12),repeat,smooth,mipMapping,resolution);
            var back_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(32, 20), 8, 12),repeat,smooth,mipMapping,resolution);
            var left_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(29, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(16, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(20, 16), 8, 4),repeat,smooth,mipMapping,resolution);
            var bottom_body:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(28, 16), 8, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            bodyml = new Object();
            bodyml.front = front_body;
            bodyml.back = back_body;
            bodyml.left = left_body;
            bodyml.right = right_body;
            bodyml.top = top_body;
            bodyml.bottom = bottom_body;
            
            // LEGR texture materials
            var front_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(4, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(12, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(4, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_legR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            legRml = new Object();
            legRml.front = front_legR;
            legRml.back = back_legR;
            legRml.left = left_legR;
            legRml.right = right_legR;
            legRml.top = top_legR;
            legRml.bottom = bottom_legR;
            
            // LEGL texture materials
            var front_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(4, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(12, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(4, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_legL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(8, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            legLml = new Object();
            legLml.front = front_legL;
            legLml.back = back_legL;
            legLml.left = left_legL;
            legLml.right = right_legL;
            legLml.top = top_legL;
            legLml.bottom = bottom_legL;
            
            // ARML texture materials
            var front_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(44, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(52, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(40, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(44, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_armL:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            armLml = new Object();
            armLml.front = front_armL;
            armLml.back = back_armL;
            armLml.left = left_armL;
            armLml.right = right_armL;
            armLml.top = top_armL;
            armLml.bottom = bottom_armL;
            
            // ARMR texture materials
            var front_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(44, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(52, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(40, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(44, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_armR:VertexLightMaterial = new VertexLightMaterial(cropBitmapData(src, new Point(48, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            armRml = new Object();
            armRml.front = front_armR;
            armRml.back = back_armR;
            armRml.left = left_armR;
            armRml.right = right_armR;
            armRml.top = top_armR;
            armRml.bottom = bottom_armR;
        }
        
        private function createPlayerMaterials(src:BitmapData):void
        {
            // Texture material settings,
            // you should probably extend TextureMaterial Rather than do this but meh
            var repeat:Boolean = false;
            var smooth:Boolean = false;
            var mipMapping:int = 0;
            var resolution:Number = 1;
            
            // HEAD texture materials
            var front_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(8, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var back_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(24, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var left_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(16, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var right_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(0, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var top_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(8, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            var bottom_head:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(16, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            headml = new Object();
            headml.front = front_head;
            headml.back = back_head;
            headml.left = left_head;
            headml.right = right_head;
            headml.top = top_head;
            headml.bottom = bottom_head;
            
            // HEADE texture materials
            var front_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(40, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var back_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(56, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var left_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var right_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(32, 8), 8, 8),repeat,smooth,mipMapping,resolution);
            var top_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(40, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            var bottom_heade:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 0), 8, 8),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            headEml = new Object();
            headEml.front = front_heade;
            headEml.back = back_heade;
            headEml.left = left_heade;
            headEml.right = right_heade;
            headEml.top = top_heade;
            headEml.bottom = bottom_heade;
            
            // BODY texture materials
            var front_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(20, 20), 8, 12),repeat,smooth,mipMapping,resolution);
            var back_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(32, 20), 8, 12),repeat,smooth,mipMapping,resolution);
            var left_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(29, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(16, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(20, 16), 8, 4),repeat,smooth,mipMapping,resolution);
            var bottom_body:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(28, 16), 8, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            bodyml = new Object();
            bodyml.front = front_body;
            bodyml.back = back_body;
            bodyml.left = left_body;
            bodyml.right = right_body;
            bodyml.top = top_body;
            bodyml.bottom = bottom_body;
            
            // LEGR texture materials
            var front_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(4, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(12, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(4, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_legR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(8, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            legRml = new Object();
            legRml.front = front_legR;
            legRml.back = back_legR;
            legRml.left = left_legR;
            legRml.right = right_legR;
            legRml.top = top_legR;
            legRml.bottom = bottom_legR;
            
            // LEGL texture materials
            var front_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(4, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(12, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(8, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(0, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(4, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_legL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(8, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            legLml = new Object();
            legLml.front = front_legL;
            legLml.back = back_legL;
            legLml.left = left_legL;
            legLml.right = right_legL;
            legLml.top = top_legL;
            legLml.bottom = bottom_legL;
            
            // ARML texture materials
            var front_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(44, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(52, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(40, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(44, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_armL:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            armLml = new Object();
            armLml.front = front_armL;
            armLml.back = back_armL;
            armLml.left = left_armL;
            armLml.right = right_armL;
            armLml.top = top_armL;
            armLml.bottom = bottom_armL;
            
            // ARMR texture materials
            var front_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(44, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var back_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(52, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var left_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(40, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var right_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 20), 4, 12),repeat,smooth,mipMapping,resolution);
            var top_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(44, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            var bottom_armR:TextureMaterial = new TextureMaterial(cropBitmapData(src, new Point(48, 16), 4, 4),repeat,smooth,mipMapping,resolution);
            
            // add materials to global object for easy access
            armRml = new Object();
            armRml.front = front_armR;
            armRml.back = back_armR;
            armRml.left = left_armR;
            armRml.right = right_armR;
            armRml.top = top_armR;
            armRml.bottom = bottom_armR;
        }
        
        private function setupUI():void
        {
            ui = new Sprite();
            
            var vox:VBox = new VBox(ui);
            vox.x = 10;
            vox.y = 40;
            vox.spacing = 12;
            
            var info:Label = new Label(ui, 10, 10, "http://davidejones.com");
            
            controller.disable();
            
            for (var i:int = 0; i < 2; i++) {
                var chk:CheckBox = new CheckBox(vox, 0, 0, ["VERTEX LIGHT", "FREE MOVE"][i], onClickCheckBox);
                chk.tag = i;
                chk.selected = false;
            }
            
            addChild(ui);
        }
        
        private function onClickCheckBox(e:MouseEvent):void
        {
            var rb:CheckBox = e.currentTarget as CheckBox;
            switch(rb.tag) 
            {
                case 0:
                    remove();
                    (rb.selected) ? createPlayerLightMaterials(bd)  :  createPlayerMaterials(bd);
                    start();
                    break;
                case 1:
                    (rb.selected) ? controller.enable() : controller.disable();
                    break;
            }
        }
        
        private function remove():void 
        {
            player.removeChild(head);
            player.removeChild(headE);
            player.removeChild(body);
            player.removeChild(legL);
            player.removeChild(legR);
            player.removeChild(armL);
            player.removeChild(armR);
        }
        
        private function cropBitmapData(sourceBitmapData:BitmapData, startPoint:Point, width:Number, height:Number):BitmapData
        {
            var croppedBD:BitmapData = new BitmapData(width, height, true);
            croppedBD.copyPixels(sourceBitmapData, new Rectangle(startPoint.x, startPoint.y, width, height), new Point(0, 0));
            return croppedBD.clone();
            croppedBD.dispose();
        }
        
        private function onResize(e:Event = null):void {
            camera.view.width = stage.stageWidth;
            camera.view.height = stage.stageHeight;
        }
        
    }
}