Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

How to use removeMovieClip for unknown number of instances

1st Flash Project:

I dynamically load multiple instances of a movie clip like this:

for(i=0;i<fcount;i++){
      attachMovie("m_tldot","m_tldot"+i,i);
}

I never know ahead of time how many fcount loaded the last time.  Is there a way to determine how many instance are in use and then use removeMovieClip to get rid of them?

Thanks
0
dtburdick
Asked:
dtburdick
  • 2
  • 2
1 Solution
 
BillystyxCommented:
yes, make an array for this:

myArr=[];
for(i=0;i<fcount;i++){
     attachMovie("m_tldot","m_tldot"+i,i);
myArr.push("m_tldot"+i);

}
when it is done, you can access the array with
_root[myArr[i]]._removeMovieClip();

Billystyx
0
 
DavidCrossmanCommented:
You could use the array or even just something like:
removingClips = true;
i=0;
while removingClips {
  var tmpMC:MovieClip = new MovieClip();
  tmpMC = eval("m_tldot"+i);
  if tmpMC <> undefined {
    tmpMC.removeMovieClip();
  } else {
    removingClips = false;
  }
}

Now that I wrote it, BillyStyx's is probably a cleaner method. If you're comfortable with arrays, definitely go that way.

In either case, you can get references to the clips to do other things to them as well as removing them.

David
-=-
0
 
dtburdickAuthor Commented:
Thanks folks.  It didn't solve my issue, but that is my problem, not yours.

I will try your method as my array just keeps getting bigger and bigger.  I'm comfortable with arrays, but I'm not used to actionscript yet.
0
 
BillystyxCommented:
to remove the elements from the array use
myArr.splice(i,1);
or
myArr.pop();//removes from end of array and returns value
or
myArr.shift();//reoves the 1st element from the array and returns the value

does this help?
Billystyx
0
 
dtburdickAuthor Commented:
Oops, I feel bad.  I implemented DavidCrossman's solution and it solved my problem.  I already gave my points to Billystyx.  Honestly you are probably both right and I just don't know what I'm doing.

Thanks to both of you.

I had to fix your code a bit, though.  It was missing some parethises and an incrementer for i:

removingClips = true;
i=0;
while (removingClips) {
  var tmpMC:MovieClip = new MovieClip();
  tmpMC = eval("m_tldot"+i);
  if (tmpMC <> undefined) {
    tmpMC.removeMovieClip();
  } else {
    removingClips = false;
  }
  i=i+1;
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now