// ActionScript file package { //import flash.display.Sprite; import flash.display.*; import flash.events.*; import flash.ui.*; import flash.net.URLRequest; import flash.text.*; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; import sandy.core.data.*; import sandy.core.Scene3D; import sandy.core.scenegraph.*; import sandy.materials.*; import sandy.materials.attributes.*; import sandy.primitive.*; import sandy.util.*; import sandy.events.*; public class script_sandy_steve_Movies extends MovieClip { private var scene:Scene3D; private var camera:Camera3D; private var plane:Plane3D; private var text:TextField = new TextField(); private var clicker:Boolean = false; private var start:Boolean = true; private var ns:NetStream; private var movie:MovieClip; public function script_sandy_steve_Movies() { // We create the camera camera = new Camera3D( 400, 400 ); camera.z = -600; camera.lookAt(0,0,0); text.width = 400; text.x = 15; text.y = 15; // We create the "group" that is the tree of all the visible objects var root:Group = createScene(); // We create a Scene and we add the camera and the objects tree scene = new Scene3D( "scene", this, camera, root ); importTextures(); Key.initialize(stage); // Listen to the heart beat and render the scene addEventListener( Event.ENTER_FRAME, loop3D ); } // Create the scene graph based on the root Group of the scene private function createScene():Group { // Create the root Group var g:Group = new Group(); plane = new Plane3D("plane", 320, 240, 1, 1, Plane3D.XY_ALIGNED); text.text = "To select a movie please click in the browser window and press F1-F5" plane.rotateX = -30; plane.rotateZ = 90; plane.container.buttonMode = true; g.addChild (plane); this.addChild (text); return g; } // The Event.ENTER_FRAME event handler tells the world to render private function loop3D (event:Event) : void { stage.addEventListener(KeyboardEvent.KEY_DOWN, zapper); plane.container.addEventListener(MouseEvent.MOUSE_DOWN, toggleSWF); plane.container.addEventListener(MouseEvent.MOUSE_DOWN, toggleFLV); scene.render(); } public function importTextures() : void { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, importCompletedMovie); loader.load(new URLRequest("../assets/student/steve/logo.swf")); } public function importCompletedMovie (event:Event) : void { var target = event.target; var motor = target.loader.content; movie = new MovieClip(); movie.addChild(target.loader.content); var material:MovieMaterial = new MovieMaterial (movie); plane.appearance = new Appearance (material); } private function zapper(event:KeyboardEvent) : void { var flvClip:Video = new Video (800, 600); var material:VideoMaterial = new VideoMaterial (flvClip, 25); var app:Appearance = new Appearance (material); plane.appearance = app; var nc:NetConnection = new NetConnection(); nc.connect(null); ns = new NetStream(nc); flvClip.attachNetStream(ns); var listener:Object = new Object(); listener.onMetaData = function (event:Object) : void {}; ns.client = listener; if (Key.isDown(Keyboard.F1)) { importTextures(); } else if (Key.isDown(Keyboard.F2)) { ns.play("../assets/student/steve/movingBlocks.flv"); } else if (Key.isDown(Keyboard.F3)) { ns.play("../assets/student/steve/brazil.flv"); } else if (Key.isDown(Keyboard.F4)) { ns.play("../assets/student/steve/car.flv"); } else if (Key.isDown(Keyboard.F5)) { ns.play("../assets/student/steve/franchiseBrazil.flv"); } } private function swfHandler(event:MouseEvent) : void { start = !start; //toggleSWF(); } private function toggleSWF(event:MouseEvent) : void { movie.stop(); } private function toggleFLV(event:MouseEvent) : void { ns.togglePause(); } } }