Gradient Background Class


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  *
  3.  * Gradient Background
  4.  *
  5.  * usage: var myBg =new GradientBackground(100,100,0xffffff,0x000000,4,1);
  6.  
  7.  * params: width, height, top color, bottom color, corner radius, alpha
  8.  
  9.  *
  10.  * @author Chuckanucka
  11.  * @version1.0
  12.  
  13.  **/
  14.  
  15. package com.chuck.effects{
  16.  
  17. // import needed classes
  18. import flash.display.MovieClip;
  19. import flash.display.Graphics;
  20. import flash.display.GradientType;
  21. import flash.display.SpreadMethod;
  22. import flash.geom.*;
  23.  
  24.  
  25. public class GradientBackground extends MovieClip {
  26.  
  27. public function GradientBackground(bgWidth:Number,bgHeight:Number,topColor:Number=0xffffff,bottomColor:Number=0x000000,cornerRadius:Number=0,bgAlpha:Number=1) {
  28. // gradient defaults
  29. var gradType:String=GradientType.LINEAR;
  30. var gradAlphas:Array=[1,1];
  31. var gradRatios:Array=[0,255];
  32. var sprMethod:String=SpreadMethod.PAD;
  33. var gradColors:Array;
  34.  
  35. gradColors=[topColor,bottomColor];
  36. var gradMatrix:Matrix=new Matrix ;
  37. gradMatrix.createGradientBox(bgWidth,bgHeight,Math.PI/180*90,0,0);
  38. var newBg:MovieClip=new MovieClip ;
  39. var newGraphic:Graphics=newBg.graphics;
  40. newGraphic.beginGradientFill(gradType,gradColors,gradAlphas,gradRatios,gradMatrix,sprMethod);
  41. newGraphic.drawRoundRect(0,0,bgWidth,bgHeight,cornerRadius);
  42. newBg.alpha = bgAlpha
  43. addChild(newBg);
  44. }
  45. }
  46. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.