PDA

View Full Version : duplicateMovieClip into 2 columns


chaponnel
08-02-2006, 02:52 PM
i am looping through and array to duplicate a movie clip, but i would like it to duplicate into 2 equal columns determined by the length of the array. so far i have the following code...

for (var i = 1; i<=team_array.length; i++) {
player.duplicateMovieClip("player"+(i), i);
theplayer = eval("player"+(i));
halfteam=Math.round(team_array.length/2)
if (i<=halfteam) {
yPos = getProperty(eval("player"+(i-1)), _y);
setProperty(theplayer, _y, (yPos+18));
} else if (i>halfteam) {
yPos = getProperty(eval("player"+(halfteam+i)), _y);
setProperty(theplayer, _y, (yPos+18));
setProperty(theplayer, _x, 570);
}
}

with the code, the movie clips duplicate, however, the second column duplicates its clips one on top of the other.

can anyone help?

thanks,
natalie

mooska
08-02-2006, 03:06 PM
for (i=0; i<20; i++) {
var m =clip.duplicateMovieClip("clip"+i, i, {_y:40*(Math.floor(i/2))});
if (!(i%2)) {
m._x = 20;
} else {
m._x = 80;
}
}

chaponnel
08-03-2006, 02:52 PM
thanks mooska

that script worked wonders, but, as is often the case, it's presented a new problem.

originally, i had the duplicating movie clip action starting on i=1 not i=0, but if i do that with this script the movie clips start in the right hand column which is not what i want!

these movieclips form part of a draggable list and if i start duplicating using i=0 for some reason the first movieclip in the list (clip0) is disappearing when i click on it. below the code ....

so perhaps you can help with this problem or tell me how i can start the list using i=1???

for (var i=0; i<team_array.length; i++) {
//duplicate master movie clip and load variables
var m = player.duplicateMovieClip("player"+i, i, {_y:100+(16*(Math.floor(i/2)))});
if (!(i%2)) {
m._x = 400;
} else {
m._x = 570;
}
theplayer=eval("player"+(i))
theplayer.id = team_array[i].playerid;
theplayer.initial = team_array[i].initial;
theplayer.lastname = team_array[i].lastname;
theplayer.shortname = team_array[i].shortname;
theplayer.teamname = team_array[i].teamname;
theplayer.positionid = team_array[i].positionid;
theplayer.teamid = team_array[i].teamid;


theplayer.onPress = function() {
startDrag(this, true, 20, 30, 600, 445);
this.gotoAndStop("drag");
this.swapDepths(1000);
};

mooska
08-03-2006, 03:19 PM
if you want to start from 1var m = player.duplicateMovieClip("player"+i, i, {_y:100+(16*(Math.floor((i-1)/2)))});remember that codition should look like this i<=team_array.length

The problem with dissapearing has something to do with you code you didnt show. This one shouldnt effect it.team_array = new Array(12);
for (var i = 1; i<=team_array.length; i++) {
//duplicate master movie clip and load variables
var m = player.duplicateMovieClip("player"+i, i, {_y:100+(16*(Math.floor((i-1)/2)))});
if ((i%2)) {
m._x = 400;
} else {
m._x = 570;
}
theplayer = this["player"+(i)];
theplayer.id = team_array[i].playerid;
theplayer.initial = team_array[i].initial;
theplayer.lastname = team_array[i].lastname;
theplayer.shortname = team_array[i].shortname;
theplayer.teamname = team_array[i].teamname;
theplayer.positionid = team_array[i].positionid;
theplayer.teamid = team_array[i].teamid;
theplayer.onPress = function() {
trace(this);
startDrag(this, true, 20, 30, 600, 445);
this.gotoAndStop("drag");
this.swapDepths(1000);
};
theplayer.onRelease = function() {
stopDrag();
};
}