How to reference many objects at once in Actionscript? -


so, question follows:

i have set of objects , want function use elements of set in function. can do?

for example:

i have many instances of same movieclip. want function nextframe() executed movieclips name matches keycode of key i've pressed.

how can reference these symbols @ once in "if" statement?

you'll need use loop.

assuming clips placed on timeline there few ways this.

  1. walk display list , search clips meet criteria. way can expensive if have tons of clips on stage.

    var i:int=this.numchildren; while(i--){      if(this.getchildat(i).name == namecriteria){          //do here, matches      } } 
  2. keep movie clips of class in array, , loop through array:

    var myarray:array = [mc1,mc2,mc3,mc4];//whatever movie clips instance names are...  each(var clip:movieclip in myarray){     if(clip.name == namecriteria){         //do     } } 
  3. create custom class automatically adds instance of movie clip array loop through.

    save following code in file called mykeycodeclip.as (or whatever you'd call it) next .fla file.

    package {     import flash.display.movieclip;     import flash.events.event;      public class mykeycodeclip extends movieclip {         public static var allclips:array = new array();          public function mykeycodeclip(){             this.addeventlistener(event.added_to_stage, addedtostage, false,0,true);             this.addeventlistener(event.removed_from_stage, removedfromstage,false,0,true);         }           private function addedtostage(e:event):void {             allclips.push(this);         }         private function removedfromstage(e:event):void {             for(var i:int=0; < allclips.length;i++){                 if(allclips[i] == this){                     allclips.splice(i,1);                     return;                 }             }         }     } } 

then can attach class library object. go library objects properties, , choose "export actionscript", in class input box, put: mykeycodeclip.

now whenever drop library object on stage, code file attached (which automatically adds/removes array). loop through each item so:

for each(var clip:movieclip in mykeycodeclip.allclips){     if(clip.name == namecriteria){         //do     } } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -