PDA

View Full Version : [Flash 8] Dynamic Movieclips with Dynamic Movie Clips : Help



Ogmatter
October 7th, 2007, 11:47 PM
Hello, is there a way to:
1. create an empty movieclip (zone1)
2. create a movieclip in zone1 (zone1.contentMC)
3. create an empty mask movieclip in zone1 (zone1.maskMC)
4. draw a filled rectangle into zone1.maskMC
5. set the zone1.maskMC as the mask for zone1.contentMC
6. load content at any time into zone1.contentMC

I just spent 15 minutes putting together a post only to have it say I was not logged in (session timeout I guess).. lost the post data on backspace. Here is the code I'm working with.. as you can see with the comments I've been at this for a while. I want to iterate through zone array.. setup empty movies.. then a contents and mask movie inside each movie, draw a rectangle in the mask movie and then set the mask before I put contents into the content MC.



stop();
var colorArray:Array = new Array("0xFF0000", "0x0000FF", "0x00FF00");
function drawRec(endX, endY, targetMovie:MovieClip) {
trace("drawing a mask in "+targetMovie+" with "+endX+", "+endY);
rndColor = Math.round(2*Math.random());
targetMovie.beginFill(colorArray[rndColor], 100);
targetMovie.moveTo(0, 0);
targetMovie.lineTo(endX, 0);
targetMovie.lineTo(endX, endY);
targetMovie.lineTo(0, endY);
targetMovie.lineTo(0, 0);
targetMovie.endFill();
}
function makeZones() {
atZone = 0;
for (zones in zoneArray) {
// create zone movie
this.createEmptyMovieClip("zone"+atZone, this.getNextHighestDepth());
// move new zone to it's correct x and y
this["zone"+atZone]._x = zoneArray[zones][0];
this["zone"+atZone]._y = zoneArray[zones][1];
// create contentMC
this["zone"+atZone].createEmptyMovieClip("contentMC",1 );
trace(this["zone"+atZone].contentMC);
// create Mask
this["zone"+atZone].createEmptyMovieClip("maskMC", 2);
trace(this["zone"+atZone].maskMC);
//draw Mask
drawRec(zoneArray[zones][2], zoneArray[zones][3], this["zone"+atZone].maskMC);
contentMC.setMask(maskMC);
loadMovie("images/0.jpg", contentMC);
//set the mask for the zones contentMC
atZone++;
}
}
var zoneArray:Array = new Array();
zoneArray[0] = (Array(0, 0, 250, 250));
zoneArray[1] = (Array(250, 0, 500, 250));
zoneArray[3] = (Array(0, 250, 500, 500));
//trace(zoneArray[0][0]);
makeZones();

Ogmatter
October 8th, 2007, 04:59 PM
Hello, is there a way to:
1. create an empty movieclip (zone1)
2. create a movieclip in zone1 (zone1.contentMC)
3. create an empty mask movieclip in zone1 (zone1.maskMC)
4. draw a filled rectangle into zone1.maskMC
5. set the zone1.maskMC as the mask for zone1.contentMC
6. load content at any time into zone1.contentMC

I just spent 15 minutes putting together a post only to have it say I was not logged in (session timeout I guess).. lost the post data on backspace. Here is the code I'm working with.. as you can see with the comments I've been at this for a while. I want to iterate through zone array.. setup empty movies.. then a contents and mask movie inside each movie, draw a rectangle in the mask movie and then set the mask before I put contents into the content MC.



stop();
var colorArray:Array = new Array("0xFF0000", "0x0000FF", "0x00FF00");
function drawRec(endX, endY, targetMovie:MovieClip) {
trace("drawing a mask in "+targetMovie+" with "+endX+", "+endY);
rndColor = Math.round(2*Math.random());
targetMovie.beginFill(colorArray[rndColor], 100);
targetMovie.moveTo(0, 0);
targetMovie.lineTo(endX, 0);
targetMovie.lineTo(endX, endY);
targetMovie.lineTo(0, endY);
targetMovie.lineTo(0, 0);
targetMovie.endFill();
}
function makeZones() {
atZone = 0;
for (zones in zoneArray) {
// create zone movie
this.createEmptyMovieClip("zone"+atZone, this.getNextHighestDepth());
// move new zone to it's correct x and y
this["zone"+atZone]._x = zoneArray[zones][0];
this["zone"+atZone]._y = zoneArray[zones][1];
// create contentMC
this["zone"+atZone].createEmptyMovieClip("contentMC",1 );
trace(this["zone"+atZone].contentMC);
// create Mask
this["zone"+atZone].createEmptyMovieClip("maskMC", 2);
trace(this["zone"+atZone].maskMC);
//draw Mask
drawRec(zoneArray[zones][2], zoneArray[zones][3], this["zone"+atZone].maskMC);
contentMC.setMask(maskMC);
loadMovie("images/0.jpg", contentMC);
//set the mask for the zones contentMC
atZone++;
}
}
var zoneArray:Array = new Array();
zoneArray[0] = (Array(0, 0, 250, 250));
zoneArray[1] = (Array(250, 0, 500, 250));
zoneArray[3] = (Array(0, 250, 500, 500));
//trace(zoneArray[0][0]);
makeZones();



I have been doing some reading on the forums and some are saying you need to apply the mask after content is loaded into a dynamically created movie, so I had the bright I idea of drawing a rec into the contentMC to see if the mask would work then... it didn't but here is the new code either way


stop();
var colorArray:Array = new Array("0xFF0000", "0x0000FF", "0x00FF00");
function drawRec(endX, endY, targetMovie:MovieClip, thisColor) {
trace("drawing a rec in "+targetMovie+" with "+endX+", "+endY);
if (thisColor != "") {
rndColor = thisColor;
} else {
rndColor = Math.round(2*Math.random());
}
targetMovie.beginFill(colorArray[rndColor]);
targetMovie.moveTo(0, 0);
targetMovie.lineTo(endX, 0);
targetMovie.lineTo(endX, endY);
targetMovie.lineTo(0, endY);
targetMovie.lineTo(0, 0);
targetMovie.endFill();
}
function makeZones() {
atZone = 0;
for (zones in zoneArray) {
// create zone movie
this.createEmptyMovieClip("zone"+atZone, this.getNextHighestDepth());
// move new zone to it's correct x and y
this["zone"+atZone]._x = zoneArray[zones][0];
this["zone"+atZone]._y = zoneArray[zones][1];
// create contentMC
this["zone"+atZone].createEmptyMovieClip("contentMC", 1);
drawRec(zoneArray[zones][2], zoneArray[zones][3], this["zone"+atZone].contentMC, "0x000000");
trace("created contentMC at "+this["zone"+atZone].contentMC);
// create Mask
this["zone"+atZone].createEmptyMovieClip("maskMC", 2);
trace("created maskMC at "+this["zone"+atZone].maskMC);
//draw Mask
drawRec(zoneArray[zones][2], zoneArray[zones][3], this["zone"+atZone].maskMC);
//this["zone"+atZone].contentMC.setMask(this["zone"+atZone].maskMC);
//loadMovie("images/0.jpg", contentMC);
//set the mask for the zones contentMC
atZone++;
}
}
var zoneArray:Array = new Array();
zoneArray[0] = (Array(0, 0, 250, 250));
zoneArray[1] = (Array(250, 0, 500, 250));
zoneArray[3] = (Array(0, 250, 500, 500));
//trace(zoneArray[0][0]);
makeZones();

js916
October 18th, 2007, 01:25 AM
Hey Og - I just posted my first message and I think I'm trying to do the same - you can search my post by author "js916". Instead of drawing a rectangle, I tried to create a button holding a movie clip. That movie clip has a transparent button on its timeline.. short story - it dodnt work. Did you find a solution?