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 19 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/v8NH
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    [SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]
    public class AS120619_02 extends Sprite {
        public var sw:Number=stage.stageWidth;
        public var sh:Number=stage.stageHeight;
        public var _myRect:myRect;
        public var _mySprite:mySprite;
        public var _myArray:Array = new Array();
        public var myNum:Number = 23.25;
        public var max:Number=400;

        public function AS120619_02() {

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

                _mySprite = new mySprite();
                _mySprite.x=i%20*myNum + myNum/2;
                _mySprite.y=Math.floor(i/20)*myNum + myNum/2;
                addChild(_mySprite);

                _myRect= new myRect(myNum);
                _mySprite.addChild(_myRect);
                _myRect.x=-myNum/2;
                _myRect.y=-myNum/2;
                _mySprite.addChild(_myRect);
                _myArray.push(_mySprite);
            
            }
            addEventListener(Event.ENTER_FRAME,xEnter);
        }
        public function xEnter(e:Event):void {
            for (var i:Number=0; i<max; i++) {
                _myArray[i].myAct();
            }
        }
    }
}


import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
class myRect extends Sprite {
    public function myRect(_myNum:Number) {
        this.graphics.beginFill(Math.random()*0xFFFFFF,1);
        this.graphics.drawRect(0,0,_myNum,_myNum);
        this.graphics.endFill();
    }
}

class mySprite extends Sprite {
    public var myInt:Number=0;
    public var myPx:Number = 1;
    public var myPy:Number = 1;
    public var myFlag:Boolean=false;
    public function mySprite() {
    }
    public function myAct():void {
        this.addEventListener(MouseEvent.MOUSE_OVER,xOver);
    }
    public function xOver(e:MouseEvent):void {
        myFlag=true;
        this.addEventListener(Event.ENTER_FRAME,xEnter2);
    }
    public function xEnter2(e:Event):void {
        if (myFlag) {
            myInt+=0.05;
            myPx -= 0.01;
            myPy -= 0.01;
            if (myInt>=10) {
                myFlag=false;
            }
        }
        if ((!myFlag) && (myInt > 0)) {
            myInt-=0.05;
            myPx += 0.01;
            myPy += 0.01;
            if (myInt<0.9){
                this.rotation =0;
                this.scaleX = 1;
                this.scaleY = 1;
            }
        }
        this.rotation+=myInt;
        this.scaleX = myPx;
        this.scaleY = myPy;
    }
}