3 Replies Latest reply on Aug 31, 2010 11:58 AM by kglad

    How to use Movie Clips in arrays?

    Graham vdR Level 1

      Hi there

       

      I'm trying to learn how to use arrays. Specifically, I'm trying to use an array to control a set of movie clips ("box1" - "box8") contained within a parent movie clip ("boxes"). I've looked at the help pages and tried to apply what I learnt to my situation. Below is my code, but I'm not sure if I'm completely missing the mark. There seems to be a problem with how I'm trying to address the elements of the array in my if/else statement.

       

      Any advice?

       

      (I'm using AS2 in CS3.)

       

       

      var mouseListener:Object = new Object();
      var scale:Number;
      var scaleBig:Number = 200;
      var scaleSmall:Number = 100;

       

      var boxArray:Array = [boxes.box1, boxes.box2, boxes.box3, boxes.box4, boxes.box5, boxes.box6, boxes.box7, boxes.box8];

       

      boxes.onRollOver = function(){
          Mouse.addListener(mouseListener);
      }
      boxes.onRollOut = function(){
          Mouse.removeListener(mouseListener);
      }

       

      mouseListener.onMouseMove = function(){
          for(var box:String in boxArray){
              scale = (scaleBig - (Math.abs(_xmouse - [box]._x)));
              if(scale > scaleSmall){
                  [box]._xscale = scale;
              }else{
                  [box]._xscale = scaleSmall;
              }
          }
      }

        • 1. Re: How to use Movie Clips in arrays?
          kglad Adobe Community Professional & MVP

          use:

           


           

           

          var mouseListener:Object = new Object();
          var scale:Number;
          var scaleBig:Number = 200;
          var scaleSmall:Number = 100;

           

          var boxArray:Array = [boxes.box1, boxes.box2, boxes.box3, boxes.box4, boxes.box5, boxes.box6, boxes.box7, boxes.box8];

           

          boxes.onRollOver = function(){
              Mouse.addListener(mouseListener);
          }
          boxes.onRollOut = function(){
              Mouse.removeListener(mouseListener);
          }

           

          mouseListener.onMouseMove = function(){
              for(var box:String in boxArray){
                  scale = (scaleBig - (Math.abs(_xmouse - boxArray[box]._x)));
                  if(scale > scaleSmall){
                      boxArray[box]._xscale = scale;
                  }else{
                      boxArray[box]._xscale = scaleSmall;

                  }
              }
          }

          • 2. Re: How to use Movie Clips in arrays?
            Graham vdR Level 1

            Ah! I need to tweak my values, but the principle seems to be working now. I hoped it was just a small syntax mistake on my part, so I'm relieved to see that it was indeed an easy fix. Thanks very much!

            • 3. Re: How to use Movie Clips in arrays?
              kglad Adobe Community Professional & MVP

              you're welcome.