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

DrawBoard3D (Flash IDE version)

Get Adobe Flash player
by bradsedito 17 Dec 2011
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/92wE
 */

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    
    public class DrawBoard3D extends Sprite 
    {
        // No code here! everything under the pub function 'DrawBoard3D()' can 
        // be copied into the Flash IDE timeline for compilation.
        
        public function DrawBoard3D() 
        {
            // ENTRY POINT:
            stage.quality = "medium";
            var frame:Sprite = Sprite(addChild(new Sprite()));
            with (frame.graphics) beginFill(0xCCCCCC), drawRect(-200, -200, 400, 400), endFill();
            frame.x = stage.stageWidth / 2;
            frame.y = stage.stageHeight / 2;
            frame.z = 100;
             
            var canvas:Shape = Shape(frame.addChild(new Shape()));
            var msk:Shape = Shape(frame.addChild(new Shape()));
            with (msk.graphics) beginFill(0x00FF00), drawRect(-200, -200, 400, 400), endFill();
            canvas.mask = msk
             
            var txt:TextField = TextField(addChild(new TextField()));
            txt.defaultTextFormat = new TextFormat("_sans", 12);
            txt.x = txt.y = 10;
            txt.textColor = 0xFFFFFF, txt.autoSize="left", txt.text = "Draw on the 3D plane...";
             
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
            function onDown(evt:MouseEvent):void{
                canvas.graphics.lineStyle(4, 0x000000);
                var pnt:Point = frame.globalToLocal(new Point(mouseX, mouseY));
                canvas.graphics.moveTo(pnt.x, pnt.y);
                addEventListener(Event.ENTER_FRAME, onDraw);
            }
            function onUp(evt:MouseEvent):void{
                removeEventListener(Event.ENTER_FRAME, onDraw);
            }
             
            var t:Number = 0;
            addEventListener(Event.ENTER_FRAME, onLoop);
            function onLoop(evt:Event):void {
                frame.rotationY = 35 * Math.sin(t);
                frame.rotationX = 35 * Math.cos(t);
                t+=0.02;
            }
             
            function onDraw(evt:Event):void {
                    var pnt:Point = frame.globalToLocal(new Point(mouseX, mouseY));
                canvas.graphics.lineTo(pnt.x, pnt.y);
            }                                 
        } // 
        
    }
}