4 Replies Latest reply on Mar 1, 2009 5:43 AM by Newsgroup_User

    Target all instances of a clip ?

      I'm learning to use flash and i'm trying to program a little game.
      I have a problem that i've been having since I started using it.
      I need to be able to target all the instances of a clip on the scene. I usually put the action script in the clip so i don't need to bother with occurence names but it doesn't work this time.
      Is there a way to target all instances of a clip on the scene ?
        • 1. Re: Target all instances of a clip ?
          Ned Murphy Adobe Community Professional & MVP
          How do you place these items on the stage?
          • 3. Re: Target all instances of a clip ?
            Ned Murphy Adobe Community Professional & MVP
            Use instance names for each object you place on the stage. You can only target/act on one item at a time, but if you name them in a sequential manner, such as mc1, mc2, mc3, etc... you can use a loop to target and act upon them in the equivalent of one shot (your eyes won't know the difference).

            for(i=1; i<totalMCs; i++){
            this["mc"+i]. doSomething;

            You could always place them all inside another movieclip and indirectly impact them all at once via targeting that movieclip, but this would only be useful when doing something like making them all visible or not.
            • 4. Re: Target all instances of a clip ?
              Level 7
              In addition to what NedWebs said you can also do a simple class that extends
              MovieClip -

              class MyReg extends MovieClip
              function MyReg()
              this.onEnterFrame = reg;
              function reg()
              delete this.onEnterFrame;

              This will call a register function in the root (I don't usually use root but
              it works for this sample.) and pass the instance to it.

              You register() would look something like so:

              var registeredItems = new Array();
              function register(clip:MovieClip){

              The benefit is not having to give all your clips instance names, which can
              sometimes be a real pain if you have a lot of them or make a lot of changes.
              To act on them you simply iterate the array:

              function moveAllItems(){
              for(var i = 0; i < registeredItems.length; i++){
              registeredItems .doSomething();

              Dave -
              Adobe Community Expert