As far as I understand, you are using a simple MovieClip
object in your code (cal_mc is of type MovieClip
).
Short answer: There is no property "color" on MovieClip
, so your first condition fails.
Long answer:
MovieClips by definition are dynamic objects, so that means they can have properties defined while your code is running:
var custom:MovieClip = new MovieClip();
custom.potato = "I am a potato!"; // creates a new property "potato" and assigns it the value of "I am a potato".
trace(custom.potato); // outputs "I am a potato";
There is no property "color" on MovieClip
, so your condition statement is false in the theoretical state, but practically flash doesn't throw any errors, since MovieClip
s can have properties assigned at runtime, so flash cannot know, If you haven't defined "color" somewhere.
The are few solutions:
- Either to create a custom class extending the
MovieClip
which would contain color
property and some methods to draw the graphics you want and logic to assign the correct value to the color
property when the drawing is complete.
- If your
MovieClip
is a simple shape, which I assume it is — render the MovieClip
to Bitmap
object, and then sample the first pixel (since all of the pixels of simple shapes are of the same color) from the Bitmap
s bitmapData
.
Here's the code for the latter: (this code may require tweaking, it's an outline)
function sampleColorFromDisplayObject(display:DisplayObject):uint
{
var bd:BitmapData = new BitmapData(display.width, display.height, false, 0xFF0000);
bd.draw(display, new Matrix());
var color:uint = bd.getPixel(0, 0);
bd.dispose();
return color;
}
Keep in mind, that due to various possible shapes and sizes, this code may require tweaking and may not work as intended with some shapes. I've made the code working with as big amount of shapes as possible by making the bitmapData big in dimensions and sampling the first pixel to account for certain types of circles and shapes defined in the flash IDE.