movie clips and quotations and brackets oh my!

  • RabbitKing
  • Newbie
  • Newbie
  • RabbitKing
  • Posts: 9
  • Loc: Camp Victory, Iraq

Post 3+ Months Ago

Evening everyone,
I've run into another silly coding problem and I'm hoping that someone can help me out.

I'm trying to dynamically create new movieclips at runtime using a while loop:

Code: [ Select ]
_global.totalRecords = 5;
i = 1;
while(i <= _global.totalRecords) {
   _root.createEmptyMovieClip(["personalitiesBox"+i], 0);
     with((_root["personalitiesBox"+i])) {
        random drawing code
        random drawing code
        random drawing code
     }
i = i+1
}
  1. _global.totalRecords = 5;
  2. i = 1;
  3. while(i <= _global.totalRecords) {
  4.    _root.createEmptyMovieClip(["personalitiesBox"+i], 0);
  5.      with((_root["personalitiesBox"+i])) {
  6.         random drawing code
  7.         random drawing code
  8.         random drawing code
  9.      }
  10. i = i+1
  11. }

now the problem that I'm having is that I need the name of new EmptyMovieClip to be surrounded with quotations. (a string) e.g.
Code: [ Select ]
_root.createEmptyMovieClip("dataStore", 0);

This seems simple, but I've tried every type of work around I could think of to no avail.

Any help would be fantastic,
-RK
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Does changing the 0 (zero) in this line,
Quote:
_root.createEmptyMovieClip(["personalitiesBox"+i], 0);

To an i fix your problem ?
Quote:
_root.createEmptyMovieClip(["personalitiesBox"+i], i);


Each iteration of that loop is overwriting the last mC created since they are all being created at 0 depth.

_global.totalRecords can also be used as just totalRecords, when the variable is defined as _global everyone knows who it is.

i = i+1 can be replaced with i++ or you can use a for loop,
Code: [ Select ]
for(var i=0; ++i<totalRecords; ){
  • RabbitKing
  • Newbie
  • Newbie
  • RabbitKing
  • Posts: 9
  • Loc: Camp Victory, Iraq

Post 3+ Months Ago

Joebert,
Once again, you've been a great help.
I found out though that my syntax was just a little goofy.
I didn't need the brackets when I was refering to my movie clip a simple with ("movieClip"+i) {} worked great.

I did decide to replace the globals with local variables though. I have another MC which used the same variables and it was annoying trying to find synonyms for all of them.

Thanks again,
-RK

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.