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

昔見たコントの動きをASで

昔、TV番組のコントで階段が急に坂道になって
登っている人が滑っていくというシーンがあり
その動きに似たものをASで作ってみました。
画面クリックで階段→坂道?に切り替わります。
Get Adobe Flash player
by yuugurenote 03 Aug 2011
    Embed
/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3C7S
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;
    import flash.display.DisplayObject;
     [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]

    public class Main110803_01 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var max:Number=12;
        public var myLineAr:Array = new Array();

        private var myGravity:Number=0.1;
        private var myBounce:Number=-0.2;
        private var _myCircle:myCircle;

        public var lineX:Number;//Array(-50,50,100,-100,-150,150,200,-200,-200);
        public var lineY:Number;//Array(-50,-50,100,100,-150,-150,200,200,-200);
        public var posX:Array=new Array(350,350,300,300,250,250,200,200,150,150,100,100);
        public var posY:Array=new Array(100,100,150,150,200,200,250,250,300,300,350,350);
        public var r:Number;

        public var myLine:_myLine;
        
        public var myFlag:Boolean = false;

        public function Main110803_01() {

            for (var i:Number=0; i<max; i++) {

                //ラインを配置
                for (var j:Number=0; j<max; j++) {
                    if (i%2==0) {
                        lineX=50;
                        lineY=0;
                        r=0;
                    } else {
                        lineX=0;
                        lineY=50;
                        r=0;
                    }
                }

                myLine=new _myLine(lineX,lineY);
                myLine.x=posX[i];
                myLine.y=posY[i];
                myLine.rotation=r;
                addChild(myLine);
                myLineAr.push(myLine);
            }


            //円を配置
            _myCircle=new myCircle  ;
            _myCircle.x=sw/2;
            _myCircle.y=0;
            addChild(_myCircle);

            addEventListener(Event.ENTER_FRAME,xEnter);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,flagClick);

        }
        private function flagClick(e:Event):void {
            if (myFlag) {
                myFlag = false;
            } else {
            myFlag = true;
            }
        }
            
        private function xEnter(e:Event):void {
            
            if (myFlag) {
                for (var ii:Number=0;ii<max;ii++) {
                    if (ii%2 == 0) {
                        myLineAr[ii].rotation =-45;
                    } else {
                        myLineAr[ii].rotation = 0;
                    }
                }
            } else {
                for (var iii:Number=0;iii<max;iii++) {
                    if (iii%2 == 0) {
                        myLineAr[iii].rotation = 0;
                    } else {
                        myLineAr[iii].rotation = 0;
                    }
                }
            }
                                    

            _myCircle.vy+=myGravity;
            _myCircle.x+=_myCircle.vx;
            _myCircle.y+=_myCircle.vy;

            if (_myCircle.y>sh) {
                _myCircle.y=0;
                _myCircle.x=sw/2;
                _myCircle.vx=0;
                _myCircle.vy=0;

            }

            for (var i:Number=0; i<max; i++) {
                myChk(myLineAr[i]);
            }

        }

        private function myChk(ActiveLine:Sprite):void {

            var myBound:Rectangle=ActiveLine.getBounds(this);

            if (_myCircle.x>myBound.left&&_myCircle.x<myBound.right) {

                var angle:Number=ActiveLine.rotation*Math.PI/180;
                var cos:Number=Math.cos(angle);
                var sin:Number=Math.sin(angle);

                var x1:Number=_myCircle.x-ActiveLine.x;
                var y1:Number=_myCircle.y-ActiveLine.y;
                var y2:Number=cos*y1-sin*x1;


                if (y2>- _myCircle.height/2) {
                    var x2:Number=cos*x1+sin*y1;

                    var vx1:Number=cos*_myCircle.vx+sin*_myCircle.vy;
                    var vy1:Number=cos*_myCircle.vy-sin*_myCircle.vx;

                    y2=- _myCircle.height/2;
                    vy1*=myBounce;

                    x1=cos*x2-sin*y2;
                    y1=cos*y2+sin*x2;
                    _myCircle.vx=cos*vx1-sin*vy1;
                    _myCircle.vy=cos*vy1+sin*vx1;
                    _myCircle.x=ActiveLine.x+x1;
                    _myCircle.y=ActiveLine.y+y1;
                }
            }
        }
    }
}
import flash.display.Sprite;

class myCircle extends Sprite {
    public var radius:Number=10;
    public var speed:Number=1;
    public var r:Number;
    public var vx:Number=0;
    public var vy:Number=0;

    public function myCircle() {
        graphics.beginFill(0xCCCCCC,1);
        graphics.drawCircle(0,0,radius);
        graphics.endFill();
    }
}


class _myLine extends Sprite {

    public function _myLine(lineX:Number,lineY:Number) {

        graphics.lineStyle(1,0x1F1F1F,0.5);
        graphics.moveTo(0,0);
        graphics.lineTo(lineX,lineY);

    }
}