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

forked from: 3D cube

Get Adobe Flash player
by alberto0000 14 Apr 2009
// forked from ll_koba_ll's 3D cube
// write as3 code here..
package {

    import flash.display.*;
    import flash.text.*;
    import flash.events.*;

    [SWF(frameRate="24", backgroundColor="#000000")]  
    public class Cube extends Sprite {

        private var sp:Sprite;
        private var faceArray:Array;
        private const CUBE_SCALE:int = 100;        
        
        public function Cube() {                        
            init();                        
        }

        private function init():void {
            createCubeFace();
            
            addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                sp.rotationY += 1;
                sp.rotationX += 1;
            });

        }

        private function createCubeFace():void {

            sp = new Sprite();
            addChild(sp);
            sp.x = 250;
            sp.y = 200;

            var s:Sprite;
            faceArray = new Array();

            function createFace(c:uint):Sprite {
                var s:Sprite = new Sprite();
                drawRect(s, c);
                sp.addChild(s);
                return s
            }
            
            // 背面
            s = createFace(0xff0000);
            s.z = CUBE_SCALE/2;

            var t:TextField = new TextField();
            s.addChild(t);
            t.text = "名古屋から\n来たFlahser";
            t.autoSize = TextFieldAutoSize.LEFT;
            t.setTextFormat(new TextFormat("_ゴシック", 15, 0xeeeeee));
            t.x = -50
            t.y = -20
            
            // 左
            s = createFace(0x0000ff);
            s.rotationY = 90;
            s.x = -CUBE_SCALE/2;
            
            // 右
            s = createFace(0x00ff00);
            s.rotationY = 90;
            s.x = CUBE_SCALE/2;
            
            // 上
            s = createFace(0xffff00);
            s.rotationX = 90;
            s.y = -CUBE_SCALE/2;

            // 下
            s = createFace(0x00ffff);
            s.rotationX = 90;
            s.y = CUBE_SCALE/2;

            // 前面
            s = createFace(0xaaaaaa);
            s.z = -CUBE_SCALE/3;

            t = new TextField();
            s.addChild(t);
            t.text = "Mañana\nSin falta";
            t.autoSize = TextFieldAutoSize.LEFT;
            t.setTextFormat(new TextFormat("_ゴシック", 15, 0xeeeeee));
            t.x = -50
            t.y = -20

            
        }


        private function drawRect(s:Sprite, c:uint):void {

            var g:Graphics = s.graphics;
            g.lineStyle(2, 0xffffff);
            g.beginFill(c, 0); // z sort してないから塗りは消しておく
            g.drawRect(-CUBE_SCALE/2, -CUBE_SCALE/2, CUBE_SCALE, CUBE_SCALE);
            g.endFill();
            
        }
        
    }
    
}