flash on 2010-2-25

by aass
♥0 | Line 51 | Modified 2010-02-25 20:49:40 | MIT License
play

ActionScript3 source code

/**
 * Copyright aass ( http://wonderfl.net/user/aass )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/adIO
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.filters.DropShadowFilter;
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.FilterShortcuts;
    
    [SWF(width=465,height=465,frameRate=30,backgroundColor=0xffffff)]
    
    import flash.ui.Mouse;
    public class FlashTest extends Sprite {
    		public static const STD_POINT:Number = 150;
    		public static const STD_DISTANCE:Number = 32;
    		public static const STD_BLUR:Number = 32;
    		
    		private var light:Sprite;
    		private var ball:Sprite;
    		
        public function FlashTest() {
            // write as3 code here..
            //FilterSHortcutsを有効化
            FilterShortcuts.init();
            
            //lightを作成
            light = new Sprite();
            light.x = stage.stageWidth / 2;
            light.y = stage.stageHeight /2;
            
            light.graphics.beginFill(0xFF0000);
            light.graphics.drawCircle(0, 0, 20);
            light.graphics.endFill();
            
            addChild(light);
            
            //ballを作成
            ball = new Sprite();
            ball.x = light.x;
            ball.y = light.y;
            ball.filters = [new DropShadowFilter(0,0,0,0.5,0,0)];
                    
            ball.graphics.beginFill(0);
            ball.graphics.drawCircle(0, 0, 20);
            ball.graphics.endFill();
            
            addChild(ball);

            //stageのクリックイベントにリスナーを登録
            stage.addEventListener(MouseEvent.CLICK, clickHandler);
       }
       private function clickHandler(evt:MouseEvent):void {
       		var dx:Number = mouseX - light.x;
       		var dy:Number = mouseY - light.y;
       		var dp:Number = Math.sqrt(dx*dx + dy*dy) / STD_POINT;
       		var degrees:Number = Math.atan2(dy, dx) / Math.PI * 180;
       		
       		Tweener.addTween(ball, {
       			x: mouseX,
       			y: mouseY,
       			_DropShadow_angle: degrees,
       			_DropShadow_distance: dp * STD_DISTANCE,
       			_DropShadow_blurX: dp * STD_BLUR,
       			_DropShadow_blurY: dp * STD_BLUR,
       			time: 1,
       			transition: "easeInOutCubic"
       		});
       }
    }
}