1. Home
  2. Computing & Technology
  3. Animation

Deconstructing the Paint Application VI: The Gradient Rectangle Tool

By Adrien-Luc Sanders, About.com

5 of 8

Defining Behavior on Mouse Release

Now that we’ve got all of our variables set up for use in the gradient fill, let’s look at the actual code executed when the mouse button is released:
if (_root.isactive=="gradientrec"){
_root.layer.lineStyle(0,_root.currentcolor,0);
diffx=_root.linex-_root._xmouse;
diffy=_root.liney-_root._ymouse;
if(diffx<0){
_root.xwidth=-diffx;
}
else{
_root.xwidth=diffx;
}
if(diffy<0){
_root.yheight=-diffy;
}
else {
_root.yheight=diffy;
}
_root.radius=(_root.base.gcangle/180)*Math.PI;
_root.layer.colors = [color1,color2];
_root.layer.alphas = [tsalpha1,tsalpha2];
_root.layer.ratios = [25,225];
_root.layer.matrix = {matrixType:"box",x:_root.linex,y:_root.liney,w:_root.xwidth,h:_root.yheight,r:_root.radius};
_root.layer.moveTo(_root.linex,_root.liney);
_root.layer.beginGradientFill("linear", _root.layer.colors, _root.layer.alphas, _root.layer.ratios,_root.layer.matrix);
_root.layer.lineTo(_root.linex,_root._ymouse);
_root.layer.lineTo(_root.linex,_root.liney);
_root.layer.lineTo(_root._xmouse,_root.liney);
_root.layer.lineTo(_root._xmouse,_root._ymouse);
_root.layer.lineTo(_root.linex,_root._ymouse);
_root.layer.endFill();
_root.rectracker.clear();
}

Scared yet? Don’t be. We’re going to break this down in three easy parts.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

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

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

All rights reserved.