Return to Snippet

Revision: 31904
at September 15, 2010 19:01 by imake


Initial Code
/**
 *
 * Gradient Background
 * 
 * usage: var myBg =new GradientBackground(100,100,0xffffff,0x000000,4,1);

 * params: width, height, top color, bottom color, corner radius, alpha 

 * 
 * @author Chuckanucka 
 * @version1.0
 
 **/
 
package com.chuck.effects{

	// import needed classes 
	import flash.display.MovieClip;
	import flash.display.Graphics;
	import flash.display.GradientType;
	import flash.display.SpreadMethod;
	import flash.geom.*;


	public class GradientBackground extends MovieClip {

		public function GradientBackground(bgWidth:Number,bgHeight:Number,topColor:Number=0xffffff,bottomColor:Number=0x000000,cornerRadius:Number=0,bgAlpha:Number=1) {
			// gradient defaults 
			var gradType:String=GradientType.LINEAR;
			var gradAlphas:Array=[1,1];
			var gradRatios:Array=[0,255];
			var sprMethod:String=SpreadMethod.PAD;
			var gradColors:Array;

			gradColors=[topColor,bottomColor];
			var gradMatrix:Matrix=new Matrix  ;
			gradMatrix.createGradientBox(bgWidth,bgHeight,Math.PI/180*90,0,0);
			var newBg:MovieClip=new MovieClip  ;
			var newGraphic:Graphics=newBg.graphics;   
			newGraphic.beginGradientFill(gradType,gradColors,gradAlphas,gradRatios,gradMatrix,sprMethod);
			newGraphic.drawRoundRect(0,0,bgWidth,bgHeight,cornerRadius);
			newBg.alpha = bgAlpha
			addChild(newBg);
		}
	}
}

Initial URL
http://activeden.net/user/Chuckanucka/portfolio?ref=Chuckanucka

Initial Description


Initial Title
Gradient Background Class

Initial Tags
class, background

Initial Language
ActionScript 3