Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Customizable Gradient Fill

Status
Not open for further replies.

AlphaSunny

Technical User
Jul 13, 2004
11
CA
I have encountered another problem passing variables into Flash (mx 2004 pro).
Simply create a flash document, in the 1st frame, write the following script for gradient fill:


var H = Stage.height;
var W = Stage.width;
var gradColorA;
var gradColorB;
if (gradColorA == undefined || gradColorA == "") {
gradColorA = 0xffff00;
}
if (gradColorB == undefined || gradColorB == "") {
gradColorB = 0x0000ff;
}
colors = [gradColorA, gradColorB];
alphas = [100, 100];
ratios = [0, 255];
rotation = 90*(Math.PI/180);
matrix = {matrixType:"box", x:0, y:0, w:300, h:300, r:rotation};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(0, 0);
lineTo(W, 0);
lineTo(W, H);
lineTo(0, H);
lineTo(0, 0);
endFill();


The published movie draws the gradient-colored square perfectly using the default colors for the 2 variables - gradColorA and gradColorB. However, it fails to do so when I try to pass the 2 variables by adding a line of code to the published html like this:

<param name="flashVars" value="gradColorA=0xffff00&gradColorB=0x00ffff" />

No matter what colors I assign to the variables, they always appear as black.

Anyone finds any problems here? Please advise, thank you in advance!

AlphaSunny
 
Add the variables to the movie parameter.

Example:
Code:
<PARAM NAME=movie VALUE="myMovie.swf?graColorA=12345&gradColorB=123345">

A slight change to your script:

Code:
var H = Stage.height;
var W = Stage.width;
var gradColorA = _root.gradColorA;
var gradColorB = _root.gradColorB;
if (gradColorA == undefined || gradColorA == "") {
	gradColorA = 0xffff00;
}
if (gradColorB == undefined || gradColorB == "") {
	gradColorB = 0x0000ff;
}
colors = [gradColorA, gradColorB];
alphas = [100, 100];
ratios = [0, 255];
rotation = 90*(Math.PI/180);
matrix = {matrixType:"box", x:0, y:0, w:300, h:300, r:rotation};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(0, 0);
lineTo(W, 0);
lineTo(W, H);
lineTo(0, H);
lineTo(0, 0);
endFill();

And you should be off to the races.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Thanks pixl8r, but this change does not make a difference as I tried out.

Can you try it out to see if it works?

Alphasunny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top