AS2: Arrays and "for" loops


hi there

 

i have simple array of movie clips ("box1" – "box6") have created on stage. have simple onrollover function iterated each of these movie clips, shown below. it's working fine, can forsee 2 potential problems when use larger arrays , apply technique real working files.

 

  1. if have many more movie clips, first line of code longer lists each movie clip instance name. there way use, example, for loop include these movie clips in array without having type out names? can see here, have used simple numerically-incremented naming process. think problem may using movie clips instance names assigned on stage , not created through actionscript.
  2. the function have created makes movie clips gotoandstop(1) , 1 has been rolled on goes frame 2. there way of making movie clips in array except 1 has been rolled on gotoandstop(1), ie. possible exclude rolled-over movie clip first part of function? here works fine is, i'm thinking maybe when start using more complex functions tweens etc may cause problems. or not?

 

 

var boxarray:array = [box1, box2, box3, box4, box5, box6];
var box:string;

 

for(box in boxarray){
   
    boxarray[box].stop();
   
    boxarray[box].onrollover = function(){
        for(box in boxarray){
            boxarray[box].gotoandstop(1);
        }
        this.gotoandstop(2);
    }
}

and further question:

 

is there way array index of specified element in array?

 

for example, in code below how array index of movie clip has been rolled over?

 

 

var myvariable:number;

var myarray:array = [mc1, mc2, mc3, mc4];  // mc1, mc2, … movie clips on stage

var mc:string;

 

for(mc in myarray){
    myarray[mc].onrollover = function(){
        myvariable = (some code here index number of rolled-over mc);
    }
}

 

 

i'd appreciate help!



More discussions in Adobe Animate CC - General


adobe

Comments

Popular posts from this blog

Hur installera Joomla på One.com - Joomla! Forum - community, help and support

removing index.php from URL address - Joomla! Forum - community, help and support

「イメージマップのアンカー名には、...」のエラーが出ないようにしたい