# \[AS3\] Compare colors by thresholds and measure the distance between them

**URL:** <https://forum.kirupa.com/t/as3-compare-colors-by-thresholds-and-measure-the-distance-between-them/238882>\
**Category:** open source\
**Created:** [September 16, 2007, 6:46pm UTC](https://forum.kirupa.com/t/as3-compare-colors-by-thresholds-and-measure-the-distance-between-them/238882 "2007-09-16T18:46:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshchernoff](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshchernoff/32/1852_2.png) [@joshchernoff](https://forum.kirupa.com/u/joshchernoff)\
**Post date:** [September 16, 2007, 6:46pm UTC](https://forum.kirupa.com/t/as3-compare-colors-by-thresholds-and-measure-the-distance-between-them/238882/1 "2007-09-16T18:46:07Z")

</div>

I made a class that you can pass two hex colors and a percent(0 - 100) to see if color2 is with in the percent of color1.

Package com.gfxcomplex.utils

Class public class CompareColors

public methodsCompareColors[INDENT]CompareColors()  
Creates a new Sprite instance.

* * *

check(color1:uint, color2:uint, margin:uint):Object  
The check method requires three arguments, color1, color2 and the margin in which to use to compare the two colors.  
Once the check method get it’s parameters it checks to see if color2 (“a hex value”) falls within color1’s (“hex value”) margin of difference.

* * *

[/INDENT]Example usage…

```auto
 
import com.gfxcomplex.utils;
var test:CompareColors = new CompareColors();
var outPut:Object = test(0xFFFFFF, 0x000000, 25);
trace(outPut.dis); //100
trace(outPut.check); //false

```

Example… [http://gfxcomplex.com/labs/colorCheck.html](http://gfxcomplex.com/labs/colorCheck.html)

source for project.  
[http://gfxcomplex.com/labs/CompareColors.zip](http://gfxcomplex.com/labs/CompareColors.zip)
