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

Cube

Get Adobe Flash player
by Kihara 06 Aug 2010
    Embed
/**
 * Copyright Kihara ( http://wonderfl.net/user/Kihara )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/l7n5
 */

package
{
    import caurina.transitions.Tweener;

    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.filters.ColorMatrixFilter;
    import flash.geom.Matrix;
    import flash.sampler.getSetterInvocationCount;
    import flash.utils.getTimer;

    import flashx.textLayout.formats.BaselineOffset;
    import flashx.textLayout.operations.SplitParagraphOperation;

    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.tweens.ITween;
    import org.osmf.display.ScaleModeUtils;
    import org.papervision3d.core.effects.view.ReflectionView;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.shadematerials.CellMaterial;
    import org.papervision3d.materials.shadematerials.EnvMapMaterial;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.materials.shadematerials.GouraudMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.view.BitmapViewport3D;

    [SWF(backgroundColor=0, width=400, height=400)]
    public class ex_sample extends ReflectionView
    {
        private var cube:Cube;
        private var cube2:Cube;
        private var light:PointLight3D;
        private var world:ReflectionView;
        private var world2:ReflectionView;
        private var sombra:Sprite = new Sprite();
        private var count:Number = 0;

        public function ex_sample()
        {
            stage.scaleMode=StageScaleMode.NO_SCALE;
            stage.align=StageAlign.TOP_LEFT;

            setup();
            Black();
            Blur();
            world.scene.addChild(cube);
            world2.scene.addChild(cube2);

            addEventListener(Event.ENTER_FRAME,onEnterFrame);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,onMouseClick);
        }

        private function setup():void{
            world = new ReflectionView();
            addChild(world);
            world2 = new ReflectionView();
            addChild(world2);

            light = new PointLight3D(true,false);

            var material:FlatShadeMaterial = new FlatShadeMaterial(light,0x2288CC,0x004466);
            var materials:MaterialsList = new MaterialsList({all:material});
            var material2:CellMaterial = new CellMaterial(light,0xFFFFFF,0x004488,15);
            var materials2:MaterialsList = new MaterialsList({all:material2});

            cube = new Cube(materials2,300,300,300,15,15,15);
            cube2 = new Cube(materials,300,300,300,15,15,15);
            cube.y = 100;
            cube2.y = 100;
            cube.x = 200;
            cube2.x = 200;

            world.surfaceHeight = -450;
            world2.surfaceHeight = -450;
            world.viewportReflection.alpha = 1;
            world2.viewportReflection.alpha = 1;
        }

        private function Black():void{
            var matr:Matrix = new Matrix();
            matr.createGradientBox(500, 150, Math.PI/2);
            sombra.graphics.beginGradientFill("linear", [0x000, 0x000], [0, 1], [0, 255], matr, "pad", "rgb", -10);
            sombra.graphics.drawRect(0, 0, 480, 200);
            sombra.graphics.endFill();
            sombra.y = 300;
            world.addChild(sombra);

        }

        private function Blur():void{
            world2.blendMode = BlendMode.ADD;
            var blur : BlurFilter = new BlurFilter();
            blur.blurX = 16;
            blur.blurY = 16;
            var matrix:Array = [0.3, 0.59, 0.11, 0, 0,
                0.3, 0.59, 0.11, 0, 0,
                0.3, 0.59, 0.11, 0, 0,
                0, 0, 0, 1, 0];
            var grayscaleFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
            world2.filters = [blur,grayscaleFilter];          
        }

        private function onMouseClick(e:MouseEvent):void{
            move(count);
            count++;
        }

        private function move(e:Number):void{
            switch(e%10){
                case 0:
                    Tweener.addTween(cube,
                        {scaleX:0.2,scaleY:2,scaleZ:0.5,time:2,delay:0.01,transition:"easeOutQuad"});
                    Tweener.addTween(cube2,
                        {scaleX:0.2,scaleY:2,scaleZ:0.5,time:2,delay:0.01,transition:"easeOutQuad"});
                    break;
                case 1:
                    Tweener.addTween(cube,
                        {scaleX:1,scaleY:0.5,scaleZ:2,time:3,delay:0.01,transition:"easeInBounce"});
                    Tweener.addTween(cube2,
                        {scaleX:1,scaleY:0.5,scaleZ:2,time:3,delay:0.01,transition:"easeInBounce"});
                    break;
                case 2:
                    Tweener.addTween(cube,
                        {scaleX:0.5,scaleY:0.5,scaleZ:0.5,rotationX:90,time:4,delay:0.01,transition:"easeInBounce"});
                    Tweener.addTween(cube2,
                        {scaleX:0.5,scaleY:0.5,scaleZ:0.5,rotationX:90,time:4,delay:0.01,transition:"easeInBounce"});
                    break;
                case 3:
                    Tweener.addTween(cube,
                        {x:300,y:300,scaleX:2,scaleY:2,scaleZ:0.1,rotationY:90,time:3,delay:0.01,transition:"easeInElastic"});
                    Tweener.addTween(cube2,
                        {x:300,y:300,scaleX:2,scaleY:2,scaleZ:0.1,rotationY:90,time:3,delay:0.01,transition:"easeInElastic"});
                    break;
                case 4:
                    Tweener.addTween(cube,
                        {scaleX:0.1,scaleY:2,scaleZ:0.1,rotationY:90,
                            time:3,delay:0.01,transition:"easeInExpo"});
                    Tweener.addTween(cube2,
                        {scaleX:0.1,scaleY:2,scaleZ:0.1,rotationY:90,
                            time:3,delay:0.01,transition:"easeInExpo"});
                    break;
                case 5:
                    Tweener.addTween(cube,
                        {x:-120,scaleX:1,scaleY:1.5,scaleZ:0.2,rotationX:20,
                            time:2,delay:0.01,transition:"easeInOutQuart"});
                    Tweener.addTween(cube2,
                        {x:-120,scaleX:1,scaleY:1.5,scaleZ:0.2,rotationX:20,
                            time:2,delay:0.01,transition:"easeInOutQuart"});
                    break;
                case 6:
                    Tweener.addTween(cube,
                        {y:100,z:200,scaleX:0.5,scaleY:0.05,scaleZ:1,rotationZ:90,
                            time:1.5,delay:0.01,transition:"easeInExpo"});
                    Tweener.addTween(cube2,
                        {y:100,z:200,scaleX:0.5,scaleY:0.05,scaleZ:1,rotationZ:90,
                            time:1.5,delay:0.01,transition:"easeInExpo"});
                    break;
                case 7:
                    Tweener.addTween(cube,
                        {x:200,z:0,scaleX:0.1,scaleY:0.1,scaleZ:0.1,rotationY:90,
                            time:3,delay:0.01,transition:"easeInOutBack"});
                    Tweener.addTween(cube2,
                        {x:200,z:0,scaleX:0.1,scaleY:0.1,scaleZ:0.1,rotationY:90,
                            time:3,delay:0.01,transition:"easeInOutBack"});
                    break;
                case 8:
                    Tweener.addTween(cube,
                        {x:-200,y:300,z:-100,scaleX:1,scaleY:1,scaleZ:2,rotationX:90,
                            time:2,delay:0.01,transition:"easeInOutBack"});
                    Tweener.addTween(cube2,
                        {x:-200,y:300,z:-100,scaleX:1,scaleY:1,scaleZ:2,rotationX:90,
                            time:2,delay:0.01,transition:"easeInOutBack"});
                    break;
                case 9:
                    back();
                    break;
                   
            }
        }

        private function back():void{
            Tweener.addTween(cube,
                {x:200,y:200,z:200,scaleX:1,scaleY:1,scaleZ:1,time:5,rotationX:180,rotationY:90,
                    delay:0.01,transition:"easeInOutElastic"});
            Tweener.addTween(cube2,
                {x:200,y:200,z:200,scaleX:1,scaleY:1,scaleZ:1,time:5,rotationX:180,rotationY:90,
                    delay:0.01,transition:"easeInOutElastic"});
            count = 0;
        }

        private function onEnterFrame(e:Event):void{

            var a:Number = Math.sin((Math.PI/1000)*getTimer());
            var b:Number = Math.cos((Math.PI/1000)*getTimer());

            cube.rotationX += 5*a+6;
            cube2.rotationX += 5*a+6;
            cube.rotationY += 3+7*b;
            cube2.rotationY += 3+7*b;
            cube.rotationZ += 4+6*a*b;
            cube2.rotationZ += 4+6*a*b;
            world.singleRender();
            world2.singleRender();
        }
    }
}