The PixelColorReader.as script will let you read all the colors of each pixel inside the stage. You will just need to call a static function and it will return you a Dictionary with the information. Note: This class doesn’t need an instance of Mono.as
How to use PixelColorReader.as
It is a really simple to use. You will just need to call the public static function readStageColors inside the class and send it the stage as parameter. You will recieve as result a Dictionary where as keys you will have the color and in value how many times it appears.
For example, imagine you want to trace all the colors with the ammount of times it appears. In order to do that, you will have to do the following:
var result:Dictionary = PixelColorReader.readStageColors(stage); for(var k:Object in result) { trace("Key: "+k+" Value: "+result[k]); }
Note that the result of calling the function is a dictionary and we iterate it showing the key and the value of each index.
Also, you will note that there is an index called TOTAL in which it will tell you the total pixels it had read in case it is needed.
Public Static Consts
- TOTAL:String = “Total”;
Public Static Functions
- readStageColors(s:Stage):Dictionary