Animation

  1. Home
  2. Computing & Technology
  3. Animation

Deconstructing the Paint Application VI: The Gradient Rectangle Tool

By Adrien-Luc Sanders, About.com

4 of 8

Number () and parseInt()

We’re still not done with that onClipEvent (enterFrame), though. We’ve got to do a little work with the strings that we’ve created from the gradient input text boxes, converting them to specific types of numeric values. This is strictly for the gradient fill and only used because we’re putting variables in the place of actual values, and wouldn’t be necessary otherwise, as you’ll see in the next step:
//convert the strings from the gradient input boxes into numeric values
tscolor1=Number(testcolor1);
color1=parseInt(tscolor1,10);
tscolor2=Number(testcolor2);
color2=parseInt(tscolor2,10);
tsalpha1=Number(_root.base.ga1);
tsalpha2=Number(_root.base.ga2);
This uses two new functions: Number() and parseInt(). The Number function has many uses, but in this case it parses the testcolor string and converts it to a decimal value, and does the same with the alpha values (which, because they’re taken from input text boxes, are initially read as strings).

The value returned for the alpha values works fine as-is, but the number returned for the gradient colors will make a bit of a mess...and so we use parseInt to convert it to an integer in base ten (decimal). parseInt takes an expression and converts it to a value in a radix/numeric base, such as octal [parseInt (expression,8)] or hexadecimal [parseInt (expression,16)].

4 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.