Applying color effect to imported image from url
I want to apply a color filter on an image that have been imported from a url. The following code (excluding the addChild line) works if the image is already added inside the Container symbol on the stage, but it doesn't work if the image is imported.
var main = this;
// Make the image a child of container
main.Container.addChild(new createjs.Bitmap("http://www.freeiconspng.com/uploads/blue-star-ball-favorites-icon-png-0.png"));
function SetColorRGB (_mc, _rgb, _saturation) {
if (_saturation == undefined) {
_saturation = 1;
}
var m = 1 - _saturation;
_mc.filters = [new createjs.ColorFilter(m, m, m, 1, _rgb[0] * _saturation, _rgb[1] * _saturation, _rgb[2] * _saturation, 0)];
_mc.cache(0, 0, _mc.nominalBounds.width, _mc.nominalBounds.height); // Update the pixels with the new color
}
// Wait 3 seconds in case the image have to load
setTimeout(ChangeColor, 3000);
function ChangeColor () {
SetColorRGB(main.Container, [255, 0, 0], 0.5);
console.log("Color filter have been applied");
}
