package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; import away3d.materials.BitmapMaterial; import away3d.primitives.Skybox6; import away3d.primitives.Sphere; import flash.display.Bitmap; import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; [SWF(width="500", height="400", frameRate="50", backgroundColor="#FFFFFF")] public class Basic08_skybox6 extends Sprite { private var cam:HoverCamera3D; private var lastKey:uint; private var keyIsDown:Boolean = false; private var View:View3D; private var cover:Cover; private var largeCube:Skybox6; /** * The following 2 lines are how graphics are embedded using Flex. * If you are using the Flash IDE, simply remove the next two * lines of code, import the image to your library and set it to * export with the class name "texture". **/ [Embed(source="resources/panoramaSpherical_out.png")] private var texture:Class; public function Basic08_skybox6() { // create a "hovering" camera cam = new HoverCamera3D(); cam.panangle = 0; cam.tiltangle = 0; cam.targetpanangle = 0; cam.targettiltangle = 0; cam.mintiltangle = -90; cam.zoom = 4; // create a viewport View = new View3D({camera:cam,x:250,y:200}); addChild(View); // add skybox6 var mat:BitmapMaterial = new BitmapMaterial( (new texture() as Bitmap).bitmapData ); largeCube = new Skybox6(mat); largeCube.quarterFaces(); View.scene.addChild(largeCube); // update the view cam.hover(); View.render(); // only run when user is above the SWF cover = new Cover(this,500,400,"Roll over and Click to activate. Use the arrow keys to navigate and S, W to zoom"); addChild(cover); // listen for key events and run every frame this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown); this.stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp); this.addEventListener(Event.ENTER_FRAME,onEnterFrame); } private function onEnterFrame(e:Event):void { if(!cover.visible) { if(keyIsDown){ // if the key is still pressed, just keep on moving switch(lastKey){ case Keyboard.UP : cam.targettiltangle -= 5; break; case Keyboard.DOWN : cam.targettiltangle += 5; break; case 87 : cam.zoom += 0.3; break; case 83 : if(cam.zoom > 1.4){cam.zoom -= 0.3}; break; case Keyboard.LEFT : cam.targetpanangle -= 5; break; case Keyboard.RIGHT : cam.targetpanangle += 5; break; } } // render the view cam.hover(); View.render(); } } private function onKeyDown(e:KeyboardEvent):void { lastKey = e.keyCode; keyIsDown = true; } private function onKeyUp(e:KeyboardEvent):void { keyIsDown = false; } } }