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 2009-11-16

Get Adobe Flash player
by AceDecade 16 Nov 2009
    Embed
package {
    import flash.display.Sprite;
    import flash.events.*;
    [SWF(frameRate="30", backgroundColor="#333333")]
    public class FlashTest extends Sprite {
        public var frame:Number;
        public var max:Number;
        public var Wingspan:Number;
        public var Bump:Number;
        public var X:Number;
        public var Y:Number;
        public var vx:Number;
        public var vy:Number;
        public var mx:Number;
        public var my:Number;
        public var rate:Number;
        public var wc:uint;
        public var bc:uint;
        public function FlashTest() {
            frame = 0;
            max = 90;
            Wingspan = 20;
            Bump = 10;
            vx = 0;
            vy = 0;
            X = 0;
            Y = stage.stageHeight/2.5;
            mx = 20;
            my = 20;
            rate = 10;
            wc = 0xcc0000;
            bc = 0x0000cc;
            stage.addEventListener(Event.ENTER_FRAME,main);
            x = stage.stageWidth/2;
            y = stage.stageHeight/2;
        }
        public function main(e:Event):void{
            frame += 1;
            if(frame == max){
                frame = 0;
            }
            vx = (mouseX-X)/rate;
            vy = (mouseY-Y)/rate;
            if(vx > mx){
                vx = mx;
            }else if(vx < -mx){
                vx = -mx;
            }
             if(vy > my){
                vy = my;
            }else if(vy < -my){
                vy = -my;
            }
            X += vx;
            Y += vy;
            if(X < -stage.stageWidth/2.3){
                X = -stage.stageWidth/2.3;
            }else if(X > stage.stageWidth/2.3){
                X = stage.stageWidth/2.3;
            }
            graphics.clear();
            //var a:Number = Math.PI*2*frame/max;
            var a:Number = -vx*Math.PI/mx/2;
            if(a > Math.PI*2){
                a -= Math.PI*2;
            }else if(a <  0){
                a += Math.PI*2;
            }
            var a2:Number = a+Math.PI;
            if(a2 > Math.PI*2){
                a2 -= Math.PI*2;
            }else if(a2 < 0){
                a2 += Math.PI*2;
            }
            drawFin(Math.max(a,a2));
            drawBody(a);
            drawFin(Math.min(a,a2));
        }
        public function drawBody(B:Number):void{
            var A:Number = B;
            if(A> Math.PI*2){
                A -= Math.PI*2;
            }else if(A < 0){
                A += Math.PI*2;
            }
            graphics.lineStyle(1,0x000000,1);
            var X1:Number = Math.cos(A)*20;
            var X2:Number = Math.cos(A+Math.PI/2)*10;
            var Y1:Number = 40;
            if(A > Math.PI){
                drawPanel([[0,-Y1],[X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,Y1],[X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,-Y1],[-X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,Y1],[-X1,Y1/3],[X2,Y1/3]],bc);
            }else{
                drawPanel([[0,-Y1],[-X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,Y1],[-X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,-Y1],[X1,Y1/3],[X2,Y1/3]],bc);
                drawPanel([[0,Y1],[X1,Y1/3],[X2,Y1/3]],bc);
            }
            if(A > Math.PI/2 && A < 3*Math.PI/2){
                drawPanel([[0,-Y1],[X1,Y1/3],[0,Y1],[-X1,Y1/3]],bc);
            }
        }
        public function drawFin(B:Number):void{
            var A:Number = B;
            if(A> Math.PI*2){
                A -= Math.PI*2;
            }else if(A < 0){
                A += Math.PI*2;
            }
            graphics.lineStyle(1,0x000000,1);
            var dx:Number = Math.sqrt(Math.pow(Wingspan,2)+Math.pow(Bump,2));
            var a:Number = Math.atan(Bump/Wingspan);
            var WX:Number = Math.cos(A)*Wingspan;
            var BX:Number = Math.cos(A)*(Wingspan+Bump);
            var X1:Number = Math.cos(A+a)*dx;
            var X2:Number = Math.cos(A-a)*dx;
            var Y1:Number = 40;
            if(A > Math.PI/2 &&A < 3*Math.PI/2){
                drawPanel([[WX,Y1],[X1,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,-Y1],[X1,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,Y1],[X2,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,-Y1],[X2,Y1/3],[BX,Y1/3]],wc);
            }else{
                drawPanel([[WX,Y1],[X2,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,-Y1],[X2,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,Y1],[X1,Y1/3],[BX,Y1/3]],wc);
                drawPanel([[WX,-Y1],[X1,Y1/3],[BX,Y1/3]],wc);
            }
            if(A > Math.PI){
                drawPanel([[WX,Y1],[X2,Y1/3],[WX,-Y1],[X1,Y1/3]],wc);
            }
        }
        public function drawPanel(A:Array,C:uint):void{
            graphics.beginFill(C);
            graphics.moveTo(X+A[0][0],Y+A[0][1]);
            for(var i:int=1;i<A.length;i++){
                graphics.lineTo(X+A[i][0],Y+A[i][1]);
            }
            graphics.lineTo(X+A[0][0],Y+A[0][1]);
        }
    }
}