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

forked from: papervision test

Get Adobe Flash player
by Johannes 28 Dec 2009
/**
 * Copyright Johannes ( http://wonderfl.net/user/Johannes )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yoxY
 */

// forked from Johannes's papervision test
package {
    import flash.events.*;
    import org.papervision3d.materials.*;
	import org.papervision3d.materials.utils.*;
	import org.papervision3d.materials.shadematerials.*;
	import org.papervision3d.lights.*;
	import org.papervision3d.objects.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.*;

	[SWF(backgroundColor='0x3CC9EE')]

	public class Sample3 extends BasicView {
		public var keyboard:Vector.<Boolean> = new Vector.<Boolean>(255);
		public var light:PointLight3D;
		public var player:Sphere;
		public var r:Number = 0;
		
        public function Sample3():void {
			light = new PointLight3D(true);
			light.x = 0;
			light.y = 100;
			light.z = 0;
			
			player = new Sphere(new FlatShadeMaterial(light, 0xFFFFFF, 0xCCCCCC), 50, 10, 8);
            
			scene.addChild(player);
            startRendering();

            addEventListener(Event.ENTER_FRAME, loop);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, kD);
			stage.addEventListener(KeyboardEvent.KEY_UP, kU);
			
			camera.target = player;
			camera.z = -400;
        }

		public function kD(e:KeyboardEvent):void {
			if(e.keyCode < 255) {
				keyboard[e.keyCode] = true;
			}
		}
		
		public function kU(e:KeyboardEvent):void {
			if(e.keyCode < 255) {
				keyboard[e.keyCode] = false;
			}
		}
        
        public function loop(e:Event):void {
			r += 0.1;
			
			light.x = player.x + (100 * Math.cos(r));
			light.z = player.z + (100 * Math.sin(r));
			
			if(keyboard[37]) {
				camera.x -= 10;
			}
			
			if(keyboard[39]) {
				camera.x += 10;
			}
			
			if(keyboard[38]) {
				camera.z += 10;
			}
			
			if(keyboard[40]) {
				camera.z -= 10;
			}
        }
    }
}