Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 08:52
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash 8 (Moderators: Jorge Solis, ..:: Mazhar Hasan ::.., Andresss)
| | |-+  Help with using movie clip instances in FOR loops
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Help with using movie clip instances in FOR loops  (Read 863 times)
Freeloader_oO
Server what's that
*
Posts: 2


View Profile
« on: 12/04/09, 13:35 »

Hi, I was wondering if someone could tell me if there is a way to use movie clip instances with FOR loops (yeh I'm not skilled with OOP so I premade mc's instead using loadMovie :<)


for example I made manual SwapDepth function between movieclips, I have hero1_mc, hero2_mc,...,hero6_mc and enemy1_mc,..., enemy12_mc. The code looks something like this:

Code:
if (_root.hero1_mc._y > _root.hero2_mc._y) {
       tempDepth1 = _root.hero1_mc.getDepth();
       tempDepth2 = _root.hero2_mc.getDepth();
     if (tempDepth2 > tempDepth1) {
               _root.hero1_mc.swapDepths(_root.hero2_mc);
     }
}
if (_root.hero1_mc._y > _root.hero3_mc._y) {
       tempDepth1 = _root.hero1_mc.getDepth();
       tempDepth2 = _root.hero3_mc.getDepth();
     if (tempDepth2 > tempDepth1) {
               _root.hero1_mc.swapDepths(_root.hero3_mc);
     }
}
...

...and so on, code works fine but if I were to write all compares manually it will be thousand lines of code to check each movie clip with each other. o_o

So I was wondering is there any way to put those movie clip instances hero1_mc, hero2_mc... into FOR loop like (code doesn't work, if there could be a way to replace numbers with variables):

Code:
for (i=1; i<18; i++) {
            for (j=1; j<18; j++) {
      if ("_root.hero"+i+"_mc" > "_root.hero"+j+"_mc") {
       .......

so I don't have to type all combinations D: so far I haven't found any way to do so, is there any way to make something similar with FOR loop and movie clips? I'm working on my project with AS2.

Thanks in advance!
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #1 on: 12/04/09, 14:51 »

if you'd work with instance names and loadMovie, it would be a lot easyer.

Make an array heroes: heroes=new Array();

the assign the moviclip to this array (in truth it is only a pointer) with

heroes[hnumber]=baseMovie.loadMovie("filename.swf");

this way you can access all the movies with heroes[hnumber], where hnumber is the number of the hero.
Logged

happy flashing
Cool
Ronald
Freeloader_oO
Server what's that
*
Posts: 2


View Profile
« Reply #2 on: 12/04/09, 15:21 »

woah it works precisely as you said  Grin

many many thanks Ronald!  Cheesy
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #3 on: 12/04/09, 15:37 »

and, as a sideefect, you got closer using objects Wink
Logged

happy flashing
Cool
Ronald
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!