• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

remove duplicate clips through array

Contributor ,
Apr 29, 2013 Apr 29, 2013

Copy link to clipboard

Copied

I'm using beneath code to two areas of clips. On the left 10 clips consisting of 2 columns and 5 rows. On the right the exact duplicate. It starts of with clip 1 on the left, than it's duplicate on the right, then clip 2 on the left, than it's duplicate on the right etc. Until both left and right have the exact same 10 clips in the same order.

Now I've added an event listener. The way I would like it to work is when I click e.g. clip 4 on the left, not only that clip should be removed, but also it's counterpart clip 4 on the right. And the same the other way: clicking clip 4 on the right should remove both the right clip 4 as the left clip 4.

The way I've got it working now is only when clicking clips on the left. That removes that clip and the clip on the right. I'm using the indexOf array way for that. By deleting the clip on that indexOf location, which would be a left clip and the clip on the right by adding 1 to that indexOf. Since in the array the right clip (duplicate) immediately follows the left (original) clip.

Of course that doesn't work the other way, when I click a right clip first. Since I then would have to subtract 1 of the indexOf location to get to the left clip version. But I can't think of a way to determine whether the clip clicked on is on the right area or the left. I've commented that second removeChild line since that doesn't work when clicking on a right clip.

Can anyone thing of a 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]);

}

TOPICS
ActionScript

Views

463

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 29, 2013 Apr 29, 2013

use:

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.name = rows+","+cols+",,"+c

...

Votes

Translate

Translate
Community Expert ,
Apr 29, 2013 Apr 29, 2013

Copy link to clipboard

Copied

use:

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.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.currentTarget.name.split(",,")[1]))));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 30, 2013 Apr 30, 2013

Copy link to clipboard

Copied

LATEST

If I've understood your code correctly, clips on the left will have even numbered indexes or 0 as their index.  Clips on the right will have odd numbered indexes.  I would try:

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]);

         if (thisclip % 2 > 0) // then thisclip is an odd uint - ie clip is on the right

          {

               removeChild(clipcopies[thisclip-1]); // remove the clip on the left

          }else{  // then thisclip is an even uint - ie clip is on theleft

               removeChild(clipcopies[thisclip+1]); // remove the clip on the right

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines