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

集約する四角形

マウス位置に小さな四角形が移動します。
マウス位置に到達するとStage内のランダムな
位置に移動して再びマウスに移動します。
Get Adobe Flash player
by yuugurenote 28 Jul 2011
/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kzGi
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;

    public class Main110728 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var max:Number = 150;
        [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]

        private var mySprite:myRect;
        private var mySprites:Array = new Array();

        public function Main110728() {
            for (var i:Number=0; i<max; i++) {
                mySprite = new myRect();
                mySprite.x=Math.random()*sw;
                mySprite.y=Math.random()*sh;
                addChild(mySprite);
                mySprites.push(mySprite);
                addEventListener(Event.ENTER_FRAME,xEnter);
            }
        }
        private function xEnter(e:Event):void {
            for (var i:Number=0; i<max; i++) {
                mySprites[i].move();
            }
        }
    }
}

import flash.display.Sprite;

class myRect extends Sprite {
    public var myInt:Number=3;
    public var speed:Number=1.5;
    public var r:Number;
    public var dx:Number;
    public var dy:Number;
    
    public function myRect() {
        graphics.beginFill(0xCCCCCC,1);
        graphics.drawRect(0,0,myInt,myInt);
        graphics.endFill();
    }
    public function move():void {
        r=Math.atan2(stage.mouseY-this.y,stage.mouseX-this.x)*180/Math.PI;
        this.x+=speed*Math.cos(r/180*Math.PI);
        this.y+=speed*Math.sin(r/180*Math.PI);
        dx = stage.mouseX - this.x;
        dy = stage.mouseY - this.y;
        if ((Math.abs(dx)<2) && (Math.abs(dy)<2)) {
            this.x = Math.random()*stage.stageWidth;
            this.y = Math.random()*stage.stageHeight;
        }
    }
}