package { import components.*; import flare.basic.*; import flare.core.*; import flare.system.*; import flash.display.*; import flash.events.*; [SWF(frameRate = 60, width = 800, height = 450, backgroundColor = 0x000000)] /** * @author Ariel Nehmad */ public class Test08_Animations2 extends Sprite { private var scene:Scene3D; private var model:Pivot3D; private var mesh:Mesh3D; private var state:String; private var backTo:String; public function Test08_Animations2() { scene = new Viewer3D( this ); scene.camera = new Camera3D(); scene.camera.setPosition( 15, 10, -20 ); scene.camera.lookAt( 0, 5, 0 ); scene.autoResize = true; scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent ); model = scene.addChildFromFile( "astronaut.zf3d" ); } private function completeEvent(e:Event):void { mesh = model.getChildByName( "astronaut" ) as Mesh3D; // we need to add the event to an animated object, not its container. // in this case, we add it to the animated mesh itself. mesh.addEventListener( Pivot3D.ANIMATION_COMPLETE_EVENT, animationCompleteEvent ); mesh.addLabel( new Label3D( "run", 0, 22 ) ); mesh.addLabel( new Label3D( "jump", 22, 65 ) ); mesh.stop(); state = "wait"; mesh.gotoAndStop( 51, 15 ); scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent ); } private function animationCompleteEvent(e:Event):void { if ( state == "jump" ) { state = backTo; if ( backTo == "run" ) mesh.gotoAndPlay( state, 5 ); else if ( backTo == "wait" ) mesh.gotoAndStop( 51, 15 ); } } private function updateEvent(e:Event):void { if ( Input3D.keyHit( Input3D.UP ) ) { state = "run"; mesh.gotoAndPlay( state, 5 ); } if ( Input3D.keyUp( Input3D.UP ) ) { state = "wait"; mesh.gotoAndStop( 51, 15 ); } if ( Input3D.keyHit( Input3D.SPACE ) && state != "jump" ) { backTo = state; state = "jump"; model.gotoAndPlay( state, 5 ); } } } }