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

review20110617

今日の授業で観た佐藤雅彦さんの動画(http://www.youtube.com/watch?v=W0W6yh0uT2o#t=7m00s)に似せて再現。

clickすると最初から動きます。
Get Adobe Flash player
by kenji_special 30 Jun 2011
    Embed
/**
 * Copyright kenji_special ( http://wonderfl.net/user/kenji_special )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vihk
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    [SWF(backgroundColor="0x0", width="465", height="465")]
    public class FlashTest extends Sprite
    {
        private var vx:int = 2;
        private var boxSp:Sprite;
        private var ball1:Sprite;
        private var ball2:Sprite;
        private var ball3:Sprite;
        private var ball4:Sprite;
        
        private var ball1vx:int;
        private var ball1vy:int;
        private var ball2vy:int;
        private var ball2vx:int;
        private var ball3vx:int;
        private var ball3vy:int;
        private var ball4vx:int;
        private var ball4vy:int;
        
        private var count2:int;
        public function FlashTest()
        {
            
            
            
            this.graphics.beginFill(0x0, 1);
            this.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            this.graphics.endFill();
            
            this.graphics.lineStyle(1, 0xffffff);
            //this.graphics.beginFill(0xff0000, 1);
            this.graphics.moveTo(0, stage.stageHeight/8);
            this.graphics.lineTo(stage.stageWidth/2, stage.stageHeight/8);
            this.graphics.lineTo(stage.stageWidth/2, stage.stageHeight/4);
            
            this.graphics.moveTo(stage.stageWidth/8, stage.stageHeight/4);
            this.graphics.lineTo(1, stage.stageHeight/4);
            this.graphics.lineTo(1, stage.stageHeight*3/8);
            
            this.graphics.moveTo(1, stage.stageHeight * 5/8);
            this.graphics.lineTo(1, stage.stageHeight * 3/4);
            this.graphics.lineTo(stage.stageWidth/8, stage.stageHeight * 3/4);
            
            this.graphics.moveTo(stage.stageWidth * 7/8,stage.stageHeight/4);
            this.graphics.lineTo(stage.stageWidth-1, stage.stageHeight/4);
            this.graphics.lineTo(stage.stageWidth-1, stage.stageHeight*3/8);
            
            this.graphics.moveTo(stage.stageWidth -1, stage.stageWidth * 5/8);
            this.graphics.lineTo(stage.stageWidth -1, stage.stageWidth * 3/4);
            this.graphics.lineTo(stage.stageWidth * 7/8, stage.stageWidth * 3/4);
            
            this.graphics.moveTo(stage.stageWidth/2, stage.stageHeight * 3/4);
            this.graphics.lineTo(stage.stageWidth/2, stage.stageHeight * 7/8);
            this.graphics.lineTo(stage.stageWidth, stage.stageHeight * 7/8);
            
            boxSp = new Sprite();
            boxSp.graphics.beginFill(0xcccccc);
            boxSp.graphics.drawRect(0, 0, stage.stageWidth/4*3, stage.stageHeight/2);
            
            boxSp.graphics.endFill();
            this.addChild(boxSp);
            
            boxSp.graphics.lineStyle(1, 0xffffff);
            boxSp.graphics.moveTo(boxSp.width/3, 0);
            boxSp.graphics.lineTo(boxSp.width/3, boxSp.height);
            
            boxSp.graphics.moveTo(boxSp.width /2 , 0);
            boxSp.graphics.lineTo(boxSp.width /2 , boxSp.height -1);
            
            boxSp.graphics.moveTo(boxSp.width/3 * 2, 0);
            boxSp.graphics.lineTo(boxSp.width/3 * 2, boxSp.height-1);
            
            ball1 = new Sprite();
            ball1.graphics.lineStyle(1,0xdddddd);
            ball1.graphics.beginFill(0xffffff);
            ball1.graphics.drawCircle(0, 0, 5);
            this.addChild(ball1);
            
            ball2 = new Sprite();
            ball2.graphics.lineStyle(1,0xdddddd);
            ball2.graphics.beginFill(0xffffff);
            ball2.graphics.drawCircle(0, 0, 8);
            this.addChild(ball2);
            
            
            ball3 = new Sprite();
            ball3.graphics.lineStyle(1,0xdddddd);
            ball3.graphics.beginFill(0xffffff);
            ball3.graphics.drawCircle(0, 0, 12);
            this.addChild(ball3);
            
            
            ball4 = new Sprite();
            ball4.graphics.lineStyle(1,0xdddddd);
            ball4.graphics.beginFill(0xffffff);
            ball4.graphics.drawCircle(0, 0, 20);
            this.addChild(ball4);
            
            
            
            init();
            boxSp.addEventListener(Event.ENTER_FRAME, boxEvent);
            stage.addEventListener(MouseEvent.CLICK, stageCli);
            
        }

        private function stageCli(event:MouseEvent):void
        {
            init();
        }

        private function boxEvent(event:Event):void
        {
            var sp:Sprite = event.target as Sprite;
            sp.x += vx;
            if(sp.x+sp.width > stage.stageWidth-1|| sp.x < 1){
                vx *=  -1;
            }
            
            
            ball1.x += ball1vx;
            ball1.y += ball1vy;
            if(ball1.x > stage.stageWidth/2){
                ball1vx = 0;
                ball1vy= 2;
            }
            
            if(ball1.y >stage.stageHeight/4 && ball1.y < stage.stageHeight * 3/4){
                ball1.x = this.localToGlobal(new Point(sp.x, sp.y)).x+sp.width * 1/2;
            }
            
            if(ball1.y > stage.stageHeight * 7/8){
                ball1vx = 2;
                ball1vy = 0;
                if(ball1.x+ ball1.width/2+1 >= stage.stageWidth){
                    ball1vx = 0;
                    ball1vy = 0;
                }
            }
            
            ball2.x += ball2vx;
            ball2.y += ball2vy;
            if(ball2.x > stage.stageWidth/2){
                ball2vx = 0;
                ball2vy= 2;
            }
            
            if(ball2.y >stage.stageHeight/4 && ball2.y < stage.stageHeight * 3/4){
                ball2.x = this.localToGlobal(new Point(sp.x, sp.y)).x+sp.width * 2/3;
            }
            
            
            
            if(ball2.y > stage.stageHeight * 7/8){
                ball2vx = 2;
                ball2vy = 0;
                if(ball2.x+ ball2.width/2+1 >= stage.stageWidth){
                    ball2vx = 0;
                    ball2vy = 0;
                }
            }
            
            
            ball3.x += ball3vx;
            ball3.y += ball3vy;
            if(ball3.x > stage.stageWidth/2){
                ball3vx = 0;
                ball3vy= 2;
            }
            
            if(ball3.y >stage.stageHeight/4 && ball3.y < stage.stageHeight * 3/4){
                ball3.x = this.localToGlobal(new Point(sp.x, sp.y)).x+sp.width * 1/2;
            }
            
            if(ball3.y > stage.stageHeight * 7/8){
                ball3vx = 2;
                ball3vy = 0;
                if(ball3.x+ ball3.width/2+1 >= stage.stageWidth){
                    ball3vx = 0;
                    ball3vy = 0;
                }
            }
            
            ball4.x += ball4vx;
            ball4.y += ball4vy;
            if(ball4.x > stage.stageWidth/2){
                ball4vx = 0;
                ball4vy= 2
            }
            
            if(ball4.y >stage.stageHeight/4 && ball4.y < stage.stageHeight * 3/4){
                ball4.x = this.localToGlobal(new Point(sp.x, sp.y)).x+sp.width * 1/3;
            }
            
            
            
            if(ball4.y > stage.stageHeight * 7/8){
                ball4vx = 2;
                ball4vy = 0;
                if(ball4.x+ ball4.width/2+1 >= stage.stageWidth){
                    ball4vx = 0;
                    ball4vy = 0;
                }
            }
            
        }
        
        private function init():void{
            
            boxSp.x =  2;
            boxSp.y = stage.stageHeight/4 ;
            
            ball1.x = 1/4 * stage.stageWidth;
            ball1.y = 1/8 * stage.stageHeight;
            ball1vx = 1;
            ball1vy = 0;
            
            ball2.x = 1/8 * stage.stageWidth;
            ball2.y = 1/8 * stage.stageHeight;
            ball2vx = 2;
            ball2vy = 0;
            
            
            ball3.x = 0;
            ball3.y = 1/8 * stage.stageHeight;
            ball3vx = 2;
            ball3vy = 0;
            
            ball4.x = - 1/8 * stage.stageWidth;
            ball4.y = 1/8 * stage.stageHeight;
            ball4vx = 2;
            ball4vy = 0;
            
            
        }
    }
}