I have a movieclip that contains code for an API drawing shape. I can use it to mask a movieclip containing an image but not a moviclip that contains a dynamic gradient. Does anyone know how to make this work?
// CREATE MASK SHAPE WITH DRAWING API
// create empty movieclip
createEmptyMovieClip("mc", 10);
// set total number of points
total = 10;
// set point & control-point coordinates
pt = [];
cp = [];
for (i=0; i<total; i++) {
pt* = {x:Math.random()*400, y:Math.random()*400};
cp* = {x:Math.random()*400, y:Math.random()*400};
}
// draw function
this.onEnterFrame = function() {
// clear the old drawing
// and draw a new one using
// the points & control-points
mc.clear();
mc.beginFill(0x0088B2, 100);
mc.moveTo(pt[0].x, pt[0].y);
for (var i = 1; i<total; i++) {
mc.curveTo(cp*.x, cp*.y, pt*.x, pt*.y);
}
mc.curveTo(cp[0].x, cp[0].y, pt[0].x, pt[0].y);
mc.endFill();
// set new positions
// for points & control-points
// and make sure they're inside stage
for (var i = 0; i<total; i++) {
pt*.x += Math.random()*4-2;
if (pt*.x<0) {
pt*.x = 0;
} else if (pt*.x>400) {
pt*.x = 400;
}
pt*.y += Math.random()*4-2;
if (pt*.y<0) {
pt*.y = 0;
} else if (pt*.y>400) {
pt*.y = 400;
}
cp*.x += Math.random()*4-2;
if (cp*.x<0) {
cp*.x = 0;
} else if (cp*.x>400) {
cp*.x = 400;
}
cp*.y += Math.random()*4-2;
if (cp*.y<0) {
cp*.y = 0;
} else if (cp*.y>400) {
cp*.y = 400;
}
}
};
// CREATE ANIMATED BACKGROUND
createEmptyMovieClip("background_mc", 1);
//trace(targetPath(_root.background_mc));
onEnterFrame = function () {
r1 = Math.sin(ra1 += .002)*50+51; //default for all: 127+128
g1 = Math.sin(ga1 += .004)*50+51;
b1 = Math.sin(ba1 += .006)*127+128;
r2 = Math.sin(ra2 += .001)*50+51;
g2 = Math.sin(ga2 += .003)*50+51;
b2 = Math.sin(ba2 += .005)*127+128;
col1 = r1 << 16 | g1 << 8 | b1;
col2 = r2 << 16 | g2 << 8 | b2;
matrix = {matrixType:"box", x:0, y:0, w:740, h:466, r:0};
with (background_mc) {
clear();
beginGradientFill("linear", [col1, col2], [100, 100], [0, 255], matrix);
lineTo(740, 0);
lineTo(740, 466);
lineTo(0, 466);
lineTo(0, 0);
endFill();
}
};
_root.background_mc._x=0;
_root.background_mc._y=0;
// SET MASKING - WORKS WITH CLIP CONTAINING IMAGE ONLY
//_root.image1.setMask(_root.mc);
_root.background_mc.setMask(_root.mc);