remove duplicate clips through array
i'm using beneath code 2 areas of clips. on left 10 clips consisting of 2 columns , 5 rows. on right exact duplicate. starts of clip 1 on left, it's duplicate on right, clip 2 on left, it's duplicate on right etc. until both left , right have exact same 10 clips in same order.
now i've added event listener. way work when click e.g. clip 4 on left, not clip should removed, it's counterpart clip 4 on right. , same other way: clicking clip 4 on right should remove both right clip 4 left clip 4.
the way i've got working when clicking clips on left. removes clip , clip on right. i'm using indexof array way that. deleting clip on indexof location, left clip , clip on right adding 1 indexof. since in array right clip (duplicate) follows left (original) clip.
of course doesn't work other way, when click right clip first. since have subtract 1 of indexof location left clip version. can't think of way determine whether clip clicked on over right area or left. i've commented second removechild line since doesn't work when clicking on right clip.
can thing of way?
var clipcopies:array = new array();
for (var rows:uint=0; rows <5; rows++)
{
for (var cols:uint= 0; cols <2; cols++)
{
for (var cops:uint=0; cops <2; cops++)
{
var persona:clips = new clips();
persona.scalex = .5;
persona.scaley = .5;
persona.gotoandstop(cols+1+rows*2);
persona.x = (cols * (persona.width+20) + 10)+(cops*300);
persona.y = (rows * (persona.height+20) + 10);
persona.addeventlistener(mouseevent.click,clickpersona);
addchild(persona);
clipcopies.push(persona);
}
}
}
function clickpersona(e:mouseevent):void
{
var thisclip:uint = clipcopies.indexof(e.target);
trace(thisclip);
removechild(clipcopies[thisclip]);
//removechild(clipcopies[thisclip+1]);
}
use:
var clipcopies:array = new array();
for (var rows:uint=0; rows <5; rows++) {
(var cols:uint= 0; cols <2; cols++) {
(var cops:uint=0; cops <2; cops++) {
var persona:clips = new clips();
persona.scalex = .5;
persona.scaley = .5;
persona.gotoandstop(cols+1+rows*2);
persona.x = (cols * (persona.width+20) + 10)+(cops*300);
persona.y = (rows * (persona.height+20) + 10);
persona.name = rows+","+cols+",,"+cops;
persona.addeventlistener(mouseevent.click,clickpersona );
addchild(persona);
clipcopies.push(persona);
}
}
}
function clickpersona(e:mouseevent):void {
removechild(movieclip(e.currenttarget));
removechild(getchildbyname(e.currenttarget.name.split(",,")[0]+",,"+(1-int(e.currenttarge t.name.split(",,")[1]))));
}
More discussions in ActionScript 3
adobe
Comments
Post a Comment