flash on 2009-5-14

by gurumi
5.Gradientの練習
♥0 | Line 85 | Modified 2009-05-15 23:28:11 | MIT License
play

ActionScript3 source code

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

//5.Gradientの練習
package
{    
	import flash.display.*;
        import flash.events.*;
	import flash.display.GradientType; 
	import flash.geom.Matrix; 
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.*;
	import org.libspark.betweenas3.tweens.ITween;

	[SWF(frameRate="24", backgroundColor="#FFFFFF")]

    public class Gradient extends Sprite
    {
        private var _t:ITween;
        private var square:Shape;
        private var square2:Shape;
 		var type:String = GradientType.LINEAR; 
		var colors:Array = [0Xff006c,0Xff00b4]; 
		var alphas:Array = [1, 1]; 
		var ratios:Array = [0, 255] ; 
		var spreadMethod:String = SpreadMethod.PAD; 
		var interp:String = InterpolationMethod.LINEAR_RGB; 
		var focalPtRatio:Number = 0; 
		 
		var matrix:Matrix = new Matrix(); 
		var boxWidth:Number = 50; 
		var boxHeight:Number = 100; 
		var boxRotation:Number = Math.PI/2;
		var tx:Number = 30; 
		var ty:Number = 10; 
       
        public function Gradient()
        {
		matrix.createGradientBox(boxWidth, boxHeight, boxRotation, tx, ty); 
		init();
		shape2();
		}
		private function init(){
		var square:Shape = new Shape; 
		square.graphics.beginGradientFill(
									type,  
									colors, 
									alphas, 
									ratios,  
									matrix,  
									spreadMethod,  
									interp,  
									focalPtRatio); 
		square.graphics.drawRect(0, 0, 200, 200);
		square.graphics.lineStyle(2,0xa1b0b6);
		addChild(square);
		square.x = 100;
		square.y = 70;
		
		
		var square2:Shape = new Shape; 
		square2.graphics.beginGradientFill(
									type,  
									[0x0303f4, 0x4d03f4], 
									[0.5,0.3], 
									ratios,  
									matrix,  
									spreadMethod,  
									interp,  
									focalPtRatio); 
		square2.graphics.drawRect(0, 0, 200, 200); 
		addChild(square2);
		square2.x = 130;
		square2.y = 100;

                
		}

                private function shape2(e:Event=null):void
                {
    _t = BetweenAS3.parallel(
           BetweenAS3.serial(
                    BetweenAS3.tween(square, {x: 420}, {x: 50}, 0.6, Cubic.easeInOut),
                    BetweenAS3.tween(square, {x: 50}, {x: 420}, 0.6, Cubic.easeInOut),
                    BetweenAS3.tween(square, {x: 420}, {x: 50}, 0.5, Cubic.easeInOut),
                    BetweenAS3.tween(square, {x: 50}, {x: 420}, 0.5, Cubic.easeInOut)
          ),
                BetweenAS3.serial(
                    BetweenAS3.tween(square2, {x:50, y: 50}, {x:420, y: 420}, 0.6, Cubic.easeInOut),
                    BetweenAS3.tween(square2, {x:420, y: 420}, {x:50, y: 50}, 0.6, Cubic.easeInOut),
                    BetweenAS3.tween(square2, {x:50, y: 50}, {x:420, y: 420}, 0.5, Cubic.easeInOut),
                    BetweenAS3.tween(square2, {x:420, y: 420}, {x:50, y: 50}, 0.5, Cubic.easeInOut)
          )
       );
            _t.play();        
			
                  
                 }	
	}
}