package { import flash.utils.*; import flash.display.Sprite; import flash.events.*; import flash.ui.*; import flash.media.Sound; import flash.display.Bitmap; import flash.display.Sprite; import flash.display.BitmapData; import flash.net.URLLoader; import flash.net.URLRequest; import fl.controls.TextArea; import flash.display.Loader; import fl.transitions.*; import fl.transitions.easing.*; import flash.text.TextField; import flash.text.TextFormat; import fl.controls.ProgressBarDirection; import fl.controls.ProgressBarMode; //wow engine import fr.seraf.wow.primitive.*; import fr.seraf.wow.constraint.*; import fr.seraf.wow.core.WOWEngine; import fr.seraf.wow.core.data.WVector; import fr.seraf.wow.math.*; // Sandy import sandy.core.Scene3D; import sandy.core.data.*; import sandy.core.scenegraph.*; import sandy.materials.*; import sandy.materials.attributes.*; import sandy.primitive.*; import sandy.events.*; public class Example033 extends Sprite { private var wow:WOWEngine; private var net:Plane3D; private var arrayWSphere:Array = new Array(); private var arrayWConstraint:Array = new Array(); private var app02:Appearance; private var material03:MovieMaterial; private var scene:Scene3D; private var camera:Camera3D; private var forwardBool:Boolean; private var pauseBool:Boolean; private var mainCaption:TextField; private var captionText:TextField; private var slashText:TextField; private var totalImages:TextField; private var currentIndex:TextField; private var textFieldFormat:TextFormat; private var nBtn:next_btn; private var pBtn:previous_btn; private var pLoad: preloader_mc; public var xmlLoader:URLLoader; private var xmlData:XML; private var bPhoto:butterfly_photo_mc; private var imageSprite:Sprite; /* Initialize imageLoader */ private var imageRequest:URLRequest; private var imageLoader:Loader; /* Arrays to store image filenames and image captions */ private var fileArray:Array; private var captionArray:Array; private var fileStr:String; /* Indexes */ private var fileArrayLength:uint; private var currentImage:int; private var i:int; /* Caption text for whole image gallery */ private var mainCaptionText:String; private var movieTimer:Timer; // Initial photo net position private var initXArray:Array; private var initYArray:Array; private var initZArray:Array; public function Example033() { forwardBool = true; pauseBool = true; //create an instance of the physic engine wow=new WOWEngine(); // SELECTIVE is better for dealing with lots of little particles colliding, wow.collisionResponseMode = wow.SELECTIVE; // gravity -- particles of varying masses are affected the same wow.addMasslessForce (new WVector(0,0,0)); var plane01:WOWPlane = new WOWPlane(); plane01.setPosition (0,60,0); plane01.elasticity=0.4; plane01.friction=0.0; //wow.addParticle (plane01); // Sandy code camera = new Camera3D( 1000, 800 ); camera.z = -250; camera.y = 50; camera.lookAt (0,0,0); var root:Group = createScene(); scene = new Scene3D( "scene", this, camera, root ); scene.light.setDirection(100, -350, 0); addEventListener ( Event.ENTER_FRAME, enterFrameHandler ); stage.addEventListener (MouseEvent.MOUSE_MOVE, mouseMovedHandler); stage.addEventListener (MouseEvent.MOUSE_DOWN, mouseClickedHandler); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); textFieldFormat = new TextFormat(); textFieldFormat.size = 32; textFieldFormat.italic = true; mainCaption = new TextField(); mainCaption.width = 800; mainCaption.height = 100; mainCaption.x = 100; mainCaption.y = 50; mainCaption.text = String(" "); mainCaption.setTextFormat(textFieldFormat,1,1); mainCaption.textColor = 0xFFFFFF; stage.addChild(mainCaption); captionText = new TextField(); captionText.multiline = true; captionText.width = 800; captionText.height = 200; captionText.x = 100; captionText.y = 650; stage.addChild(captionText); totalImages = new TextField(); totalImages.width = 75; totalImages.height = 50; totalImages.x = 500; totalImages.y = 600; stage.addChild(totalImages); currentIndex = new TextField(); currentIndex.width = 75; currentIndex.height = 50; currentIndex.x = 400; currentIndex.y = 600; stage.addChild(currentIndex); slashText = new TextField(); slashText.text = new String("/"); slashText.width = 25; slashText.height = 50; slashText.x = 475; slashText.y = 600; stage.addChild(slashText); nBtn = new next_btn(); nBtn.x = 875; nBtn.y = 175; nBtn.width = 80; nBtn.height = 250; stage.addChild(nBtn); pBtn = new previous_btn(); pBtn.x = 45; pBtn.y = 175; pBtn.width = 80; pBtn.height = 250; stage.addChild(pBtn); nBtn.addEventListener(MouseEvent.CLICK, nextClickHandler); pBtn.addEventListener(MouseEvent.CLICK, previousClickHandler); pLoad = new preloader_mc(); xmlLoader = new URLLoader(); xmlData = new XML(); fileArray = new Array(); captionArray = new Array(); fileArrayLength = 0; currentImage = 0; xmlLoader.addEventListener(Event.COMPLETE, LoadXML); xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, noFile); imageRequest = new URLRequest(); imageLoader = new Loader(); imageLoader.contentLoaderInfo.addEventListener(Event.OPEN,openProgress); imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressFunction); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadImage); var xmlFileName:String = new String("gallery-photos.xml"); /* Load filenames and image captions from file muotkatunturit-2003.xml */ xmlLoader.load(new URLRequest(xmlFileName)); var movieTimer:Timer = new Timer(100); movieTimer.addEventListener(TimerEvent.TIMER,updateMovie); //movieTimer.start(); //movieTimer.stop(); } function nextClickHandler(event:MouseEvent): void { if(currentImage < (fileArrayLength-1)) { currentImage++; } else { currentImage = 0; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 20; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); } function previousClickHandler(event:MouseEvent): void { if(currentImage > 0) { currentImage--; } else { currentImage = fileArrayLength - 1; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); trace(String(xmlData.image.filename[currentImage])); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = new String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); } private function createScene ():Group { // Create the root Group var g:Group = new Group(); net = new Plane3D( "theNet", 100, 150, 9, 9, Plane3D.ZX_ALIGNED, "quad" ); net.y = 30; net.tilt -= 40; net.enableBackFaceCulling = false; imageSprite = new Sprite(); bPhoto = new butterfly_photo_mc(); var materialAttr01:MaterialAttributes = new MaterialAttributes( new LightAttributes( true, 0.01), new LineAttributes(1, 0xFFFFFF, 1) ); var material01:Material = new ColorMaterial( 0x990000, 1, materialAttr01 ); material01.lightingEnable = false; material03 = new MovieMaterial( new init_mc() ); material03.lightingEnable = true; app02 = new Appearance( material03 ); var app01:Appearance = new Appearance( material01 ); net.appearance = app02; // vertex of the pshere for (var i:int =0; i 0) { currentImage--; } else { currentImage = fileArrayLength - 1; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); trace(String(xmlData.image.filename[currentImage])); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 20; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); break; case Keyboard.RIGHT: // v if(currentImage < (fileArrayLength-1)) { currentImage++; } else { currentImage = 0; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 20; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); break; case Keyboard.UP: currentImage = currentImage + 10; if(currentImage > (fileArrayLength-1)) { currentImage = fileArrayLength-1; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 20; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); break; case Keyboard.DOWN: currentImage = currentImage - 10; if(currentImage < 0) { currentImage = 0; } imageRequest = new URLRequest(xmlData.image.filename[currentImage]); imageLoader.load(imageRequest); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; currentIndex.text = String(currentImage+1); currentIndex.setTextFormat(textFieldFormat,0,new String(currentImage+1).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; slashText.setTextFormat(textFieldFormat,0,1); textFieldFormat = new TextFormat(); textFieldFormat.size = 22; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; totalImages.text = new String(fileArrayLength); totalImages.setTextFormat(textFieldFormat,0,new String(fileArrayLength).length); textFieldFormat = new TextFormat(); textFieldFormat.size = 20; textFieldFormat.bold = true; textFieldFormat.font = "Arial"; textFieldFormat.font = "Comic Sans MS"; textFieldFormat.align = "center"; textFieldFormat.color = 0xFFFFFF; captionText.text = captionArray[currentImage]; captionText.setTextFormat(textFieldFormat,0,new String(captionArray[currentImage]).length); break; } } private function enterFrameHandler ( event : Event ):void { //run the engine once wow.step (); for (var i=0; i= net.geometry.aVertex.length) { RAND_FIRST = Math.floor(Math.random()*net.geometry.aVertex.length); } if(forwardBool == true) { for (var i=RAND_FIRST; i imageSprite.width) { imageSprite.x =(bPhoto.width - imageSprite.width)*0.5; } if( bPhoto.height > imageSprite.height) { imageSprite.y = (bPhoto.height - imageSprite.height)*0.5; } } } }