Question
Writing a simple class
I would like to write a class that will draw a gradient for
the whole background of my file. I had written this in my file and
it was working, but I would like to put that code into a class now,
as I am trying to learn how to write classes. I am totally new to
classes, so bare with me, I don't know what I am doing... more
guessing at this point really. Here is what I have so far.
My class is called BgGradient.as and holds the following AS so far.
class BgGradient
{
var gradient01:String;
var gradient02:String;
var fillType:String = "linear";
var colors:Array = [gradient01, gradient02];
var alphas:Array = [100, 100];
var ratios:Array = [0, 255];
var matrix:Object = {matrixType:"box", x:0, y:0, w:Stage.width, h:Stage.height, r:(90/180)*Math.PI};
var spreadMethod:String = "pad";
var interpolationMethod:String = "linearRGB";
var focalPointRatio:Number = 1;
function BgGradient() {
beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
}
I would like gradient01 and gradient02 to be hex values that I can specify in my main file. What am I missing here? Do I need to import anything? How about the drawing API? How would I call this from my main file?
Thanks a lot for any help with this. I really appreciate any help!
My class is called BgGradient.as and holds the following AS so far.
class BgGradient
{
var gradient01:String;
var gradient02:String;
var fillType:String = "linear";
var colors:Array = [gradient01, gradient02];
var alphas:Array = [100, 100];
var ratios:Array = [0, 255];
var matrix:Object = {matrixType:"box", x:0, y:0, w:Stage.width, h:Stage.height, r:(90/180)*Math.PI};
var spreadMethod:String = "pad";
var interpolationMethod:String = "linearRGB";
var focalPointRatio:Number = 1;
function BgGradient() {
beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
}
I would like gradient01 and gradient02 to be hex values that I can specify in my main file. What am I missing here? Do I need to import anything? How about the drawing API? How would I call this from my main file?
Thanks a lot for any help with this. I really appreciate any help!