Animation

  1. Home
  2. Computing & Technology
  3. Animation

Deconstructing the Paint Application VI: The Gradient Rectangle Tool

By Adrien-Luc Sanders, About.com

8 of 8

Understanding the Matrix used in beginGradientFill

Lastly let’s look at the matrix itself, the last parameter required by beginGradienFill:
_root.layer.matrix = {matrixType:"box",x:_root.linex,y:_root.liney,w:_root.xwidth,h:_root.yheight,r:_root.rad};

For a single line of text, that probably looks extremely confusing. To clarify a few things first: _root.linex and _root.liney are the universal variables I’ve been using through the entire application to capture the starting x and y coordinates of the mouse when the button is first depressed. _root.xwidth and _root.yheight are variables that I created in the main code sample in order to determine the number of pixels between the starting and ending x and y coordinates of the mouse when the mouse button is released, and the check to see if the value calculated is positive or negative. If it’s negative, it converts it to positive, so we won’t have a negative width or height. _root.rad is another variable that I created to capture the angle (in degrees) of the gradient, entered by the user in an input text box, and then convert it to rotation in radians.

Now that my individual variables are explained, let’s look at the actual basic matrix format. There are two different ways to do this - either as a basic matrix, or as a matrixType. I prefer matrixType because it’s easier to “break” the code:

matrix = {matrixType, x:###, y:###, w:###, h:###, r:### };

matrixType is a string that defines the shape whose properties are being listed in the matrix, in this case a “box” type. x and y are the starting points where the drawing begins on the stage’s coordinate plane; w and h are the width and height of the box being drawn, and r is the angle in radians of the gradient. These values can be numbers or variables.

And that pretty much covers this one.

8 of 8

Explore Animation

More from About.com

Animation

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Deconstructing the Paint Application VI: The Gradient Rectangle Tool

©2008 About.com, a part of The New York Times Company.

All rights reserved.