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

flash on 2012-9-11

Get Adobe Flash player
by mutantleg 23 Oct 2012
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/c3pu
 */

package {
    import flash.ui.Keyboard;
    import flash.text.TextField;
    
    import flash.display.BlendMode;
    import flash.display.BitmapData;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    import alternativ7.engine3d.containers.*;
    import alternativ7.engine3d.core.*;
    import alternativ7.engine3d.objects.*;
    import alternativ7.engine3d.objects.Mesh;
    import alternativ7.engine3d.primitives.*;
    import alternativ7.engine3d.materials.*;
    import alternativ7.types.*;
    import alternativ7.*;
    import alternativ7.engine3d.lights.*;
  import alternativ7.engine3d.objects.Mesh;
    
    public class FlashTest extends Sprite {
        
        public var cam:Camera3D;
        public var cont:Object3DContainer = new ConflictContainer();

        public var pmesh:Box;        
        
        public var deb:TextField;
        public var vx:Number = 0;
        public var vy:Number = 0;
        public var vz:Number = 0;
        
        public function FlashTest() 
        {
            // write as3 code here..
                cam = new Camera3D();
                cam.view = new View(450,450); 
                cam.z = -1000;
                
                addChild(cam.view);
                cont.addChild(cam);
                
              deb = new TextField();
              addChild(deb);
              deb.text = Alternativa3D.version;
                
                var p:Plane;
                
                p = new Plane(1000, 1000, 8, 8);
                p.setMaterialToAllFaces( new FillMaterial(0xFF0000,1,1,0) );
                p.rotationX = 1.57;
                p.y = 200;
                p.sorting = 2;
                cont.addChild(p);
                
                pmesh = new Box(20,20,20);
                pmesh.setMaterialToAllFaces( new FillMaterial(0x0000FF,1,1,0) );
                cont.addChild(pmesh);
                
                  stage.addEventListener(Event.ENTER_FRAME, onEnter);  
                  stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
                  stage.addEventListener(KeyboardEvent.KEY_UP, kup);    
               
               
        }//ctor
        
        public var hx:Number = 1;
        public var hz:Number = 1;
        
        public function onEnter(e:Event):void
        {
            if (vecKey[Keyboard.LEFT]) { vx += hx; vz += hz;}
            if (vecKey[Keyboard.RIGHT]) { vx -= hx; vz -= hz;}
            if (vecKey[Keyboard.UP]) { vz += -hx; vx += hz;}
            if (vecKey[Keyboard.DOWN]) { vz -= -hx; vx -= hz;}
            
            vy += 0.2;
            
            vx *= 0.91;
            vz *= 0.91;
            
            pmesh.x += vx;
            pmesh.y += vy;
            pmesh.z += vz;
            
            if (vy>0 && pmesh.y >= 195) { pmesh.y = 195;vy = 0; }
            
            
            var dx:Number;
            var dz:Number;
            var a:Number;
            var k:Number;
            dx = pmesh.x - cam.x;
            dz = pmesh.z - cam.z;
            a = Math.atan2(dz, dx);
            cam.rotationY = -a +1.57;
            k = a + 1.57;
            hx = Math.cos(k);
            hz = Math.sin(k);
            
            
            var nx:Number;
            var nz:Number;
            var mag:Number;
            mag = Math.sqrt(dx*dx+dz*dz);
            if (mag == 0) { mag = 0.0000001;}
            nx = dx/mag;
            nz = dz/mag;
            
            cam.x += nx * 0.1 * (mag - 350);
            cam.z += nz * 0.1 * (mag - 350);
            cam.y = 100;
            
            
             cam.render();
             
        }//onenter
        
        public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(1024,false);
        
        public function kdown(e:KeyboardEvent):void
        {
             vecKey[e.keyCode] = true;
        }//kdown
        
        public function kup(e:KeyboardEvent):void
        {
             vecKey[e.keyCode] = false;
        }//kup
        
        
    }//flashtest
}//package