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

カラフル四角形2

空のブロックをマウスをクリックすると色がランダムの色になり
横から動いてくるラインと接触するとちょっと動きます。
Get Adobe Flash player
by yuugurenote 21 Jun 2012
    Embed
/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1yLc
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.ColorTransform;
    
    [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
    public class AS120621_01 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var _myRect:myRect;
        public var _NewRect:NewRect;
        public var _FillRect:FillRect;
        public var _myLine:myLine;
        public var _myArray:Array = new Array();
        public var _myArray2:Array = new Array();
        public var _myArray3:Array = new Array();
        public var myNum:Number=23.25;
        public var max:Number=400;
        public var px:Number;
        public var py:Number;
        public var myFlag:Boolean=false;

        public function AS120621_01() {

            //背景&追加ブロック位置設定用ブロック
            for (var i:Number=0; i<max; i++) {
                _myRect=new myRect(myNum);
                _myRect.x=i%20*myNum;
                _myRect.y=Math.floor(i/20)*myNum;
                addChild(_myRect);
                _myArray.push(_myRect);
                _myRect.addEventListener(MouseEvent.MOUSE_DOWN,xChk);
            }

            //接触ライン
            _myLine = new myLine();
            _myLine.x=_myLine.y=0;
            addChild(_myLine);

            stage.addEventListener(MouseEvent.MOUSE_DOWN,xNewRect);
            stage.addEventListener(MouseEvent.MOUSE_DOWN,xFillRect);
            addEventListener(Event.ENTER_FRAME,xEnter);
        }
        public function xChk(e:MouseEvent):void {
            px=e.target.x;
            py=e.target.y;
        }
        public function xNewRect(e:MouseEvent):void {
            _NewRect=new NewRect(myNum);
            _NewRect.x=px;
            _NewRect.y=py;
            addChild(_NewRect);
            _myArray2.push(_NewRect);
        }
        public function xFillRect(e:MouseEvent):void {
            
            var _mySprite:Sprite = new Sprite();
            _mySprite.x = px;
            _mySprite.y = py;
            addChild(_mySprite);
            
            _FillRect=new FillRect(myNum);
            _mySprite.addChild(_FillRect);
//            _FillRect.x=px;
//            _FillRect.y=py;
            _myArray3.push(_FillRect);
        }

        public function xEnter(e:Event):void {
            for (var i:Number=0; i<_myArray2.length; i++) {
                xChk2(_myArray2[i],_myLine,_myArray3[i]);
            }
        }
        private function xChk2(obj1:Sprite,obj2:Sprite,obj3:Sprite) {
            var dx:Number=obj1.x-obj2.x;
            if (Math.abs(dx)<1) {
                obj1.addEventListener(Event.ENTER_FRAME,xEnter2);
                obj3.addEventListener(Event.ENTER_FRAME,xEnter4);
            }
        }
        private function xEnter2(e:Event):void {
            e.target.alpha-=0.025;
            if (e.target.alpha<0) {
                e.target.addEventListener(Event.ENTER_FRAME,xEnter3);
                e.target.removeEventListener(Event.ENTER_FRAME,xEnter2);
            }
        }
        private function xEnter3(e:Event):void {
            e.target.alpha+=0.025;
            if (e.target.alpha>=1) {
                e.target.removeEventListener(Event.ENTER_FRAME,xEnter3);
            }
        }
        private function xEnter4(e:Event):void {
            e.target.scaleX += 0.05;
            e.target.scaleY += 0.05;
            e.target.x -= 0.57;
            e.target.y -= 0.57;
            e.target.alpha -= 0.01;
            if (e.target.alpha < 0) {
                e.target.scaleX = e.target.scaleY = 1;
                e.target.x = e.target.y = 0;
                e.target.alpha = 1;
                e.target.removeEventListener(Event.ENTER_FRAME,xEnter4);
            }
        }
    }
}

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;

class myRect extends Sprite {
    public var _myNum:Number=23.25;
    public var _NewRect:NewRect;
    public function myRect(_myNum:Number) {
        this.graphics.lineStyle(1,0xCCCCCC,1,false,"none");
        this.graphics.beginFill(0xFFFFFF,1);
        this.graphics.drawRect(0,0,_myNum,_myNum);
        this.graphics.endFill();
    }
}

class NewRect extends Sprite {
    public function NewRect(_myNum:Number) {
        this.graphics.beginFill(Math.random()*0xFFFFFF,1);
        this.graphics.drawRect(0,0,_myNum,_myNum);
        this.graphics.endFill();
    }
}

class FillRect extends Sprite {
    public function FillRect(_myNum:Number) {
        this.graphics.lineStyle(1,0xCCCCCC,1,false,"none");
        this.graphics.drawRect(0,0,_myNum,_myNum);
    }
}

class myLine extends Sprite {
    public var myFlag:Boolean=false;
    public function myLine() {
        this.graphics.lineStyle(1,0xCCCCCC,1,false,"none");
        this.graphics.moveTo(0,0);
        this.graphics.lineTo(0,465);
        this.addEventListener(Event.ENTER_FRAME,xEnter);
    }
    public function xEnter(e:Event):void {
        this.x+=1;
        if (this.x>=465) {
            this.x=0;
        }
    }
}