BackGround

Package:
Class:
Inheritance:
biz.flashscript.background
public class BackGround
Sprite
The BackGround class allows to create a colored background of objects or the timeline/stage as unicolor or gradient. To create a background use the constructor new BackGround()
Public Properties
Property Defined By
focalPointRatio : Number
To set the ratio of the focal point.
BackGround
Public Methods
Method Defined By
BackGround(color1:uint, color2:uint, fiType:String="linear", spMethod:String="pad", r1:int=0, r2:int=255, grSize:int=0, grHeight:int=0, grRot:int=0, grX:int=0, grY:int=0) BackGround
removChild():void
Removes an existing background.
BackGround
fadeBGOut():void
Fades out a background.
BackGround
fadeBGIn():void
Fades in a background.
BackGround
Events
Event Defined By
All inherited events for the Sprite class. N/A
Property Detail
focalPointRatio property
focalPointRatio:Number [read-write]

A number that controls the location of the focal point of the gradient. A value of 0 sets the focal point in the center. A value of 1 means that the focal point is at one border of the gradient circle.A value of -1 sets the focal point at the other border of the gradient circle.

The default value is 1.

Implementation

public function get focalPointRatio():Number
public function set focalPointRatio(value:Number):void
Constructor Detail
BackGround ()  Constructor
public function BackGround(color1:uint, color2:uint, fiType:String="linear", spMethod:String="pad", r1:int=0, r2:int=255, grSize:int=0, grHeight:int=0, grRot:int=0, grX:int=0, grY:int=0)
Intializes a new BackGround instance.

Parameters

  • color1:uint ____ The first color of a gradient.
  • color2:uint ____ The second color of a gradient.
  • fiType:String="linear" ____ Gradient fill: "linear", "radial" (derived from flash.display.Graphics class).
  • spMethod:String="pad" ____ Spreadmethod: "pad", "reflect", "repeat" (derived from the Graphics.beginGradientFill() method).
  • r1:int=0 ____ ratio of color 1, by default 0 (derived from the Graphics.beginGradientFill() method).
  • r2:int=0 ____ Ratio of color 2, by default 255 (derived from the Graphics.beginGradientFill() method).
  • grWidth:int=0 ____ Width of the gradient, by default when 0 it is the stage width.
  • grHeight:int=0 ____ Height of the gradient, by default when 0 it is the stage height.
  • grRot:int=0 ____ Rotation of the gradient, by default 0.
  • grX:int=0 ____ x location of the gradient, by default 0.
  • grY:int=0 ____ y location of the gradient, by default 0.
Method Detail
removChild()  method
public function removChild():void
This method will remove the background.
fadeBGOut()  method
public function fadeBGOut():void
This method will fade out the background.
fadeBGIn()  method
public function fadeBGIn():void
This method will fade in a background.
Examples
Create a new fla file and name it Background.fla. Place the fla in the same folder as the biz folder. Create a rectangle MovieClip (Clip) with a red border and no fill and export for Actionscript. Then create an Actionscript file, name it Background.as and place this script. You should see a gradient colored background. Pressing the MovieClip will change the background.

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import biz.flashscript.background.BackGround;

	public class Background extends Sprite
	{
		private var bg:BackGround;
		private var mc:Clip;
		public function Background ():void
		{
			var bgt:BackGround = new BackGround (0xFFFFFF,0x000000,"linear","pad",0,255,0,0);
			addChild(bgt);
			bgt.focalPointRatio = -1;
			mc = new Clip();
			mc.x = 100;
			mc.y = 100;
			addChild (mc);
			bg = new BackGround (0xFF0000,0xFFFF00,"linear","pad",0,255,mc.width,mc.height);
			mc.addChild(bg);
			addEventListener (MouseEvent.CLICK, cHandler);
		}
		private function cHandler (e:Event):void
		{
			bg.removChild();
			bg.fadeBGOut ();
			bg.focalPointRatio = -1;
			bg = new BackGround (0xFFFF00,0xFF0000,"radial","pad",150,255,mc.width,mc.height,0,20,0);
			mc.addChild(bg);
			bg.fadeBGIn ();
		}
	}
}