6 Replies Latest reply on Oct 31, 2010 5:01 PM by Ned Murphy

    Scaling problems with attachMovie

    IcarusFW

      I have a pretty weird scaling issue with movie clips loaded with attachMovie. At the moment, I'm trying to create a dynamic Flash site that uses attachMovie to load clips from the library based on a few set variables (loaded from PHP with LoadVars) - one container clip is loaded on the main stage with attachMovie at runtime, positioned and resized using AS2, and within the container is a number of clips again loaded with attachMovie, and organised to sit side by side.

       

      On the main timeline the code is:

       

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

      stop();

       

      MyVars = new LoadVars();

      MyVars.load ('http://spaces:8888/_materials/experiments/vartest.php');

       

      var images = new Array();

      _global.count;

       

      MyVars.onLoad = function() {

      // load count variable as array length

      _global.count = this.count;

      wall = attachMovie("container", "container", 0);

      wall._width = 400 * _global.count;

      wall._x = 0;

      wall.y = 0;

      }

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

       

       

      In the container, the code is:

       

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

      stop();

       

      init = function() {

      for (i=0; i < _global.count; i++) {

      newBox = this.attachMovie("box", "box"+i, i);

      newBox._xscale = 400 / (_global.count * 4);

      newBox._x = (400 / _global.count) * i;

      newBox._y = 0;

      newBox._alpha = 20+(Math.random()*80);

      }

      }

       

      init();

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

       

       

      Now, at present, this code functions as expected because I have had to use resizing equations to fix the box sizes - what was happening originally was that the container movieclip would be sized to the correct size, but then the nested clips inside the container would be resized by an unknown factor that makes them much bigger than the clip I'm trying to load. The result is that the clips within the container clip out of the boundary of the container.

       

      The main question is: is there anyway to use attachMovie and avoid the scaling issue I'm running into? At the moment, this is working okay, but my main concern is that when I come to load assets into the nested clips in the container movie clip, they too will be affected by the weird factorial scaling issue.

       

      The Flash file I'm working on is here: http://thestudio-uk.com/public_html/external/final_v02.fla

        • 1. Re: Scaling problems with attachMovie
          Ned Murphy Adobe Community Professional & MVP

          Is there something about the container that you need to set its size?  If you resize it, anything it contains is resized proportionally.  A container is usually best left alone, starting as an empty movieclip and filled with whatever it is deemed to contain.

          1 person found this helpful
          • 2. Re: Scaling problems with attachMovie
            kglad Adobe Community Professional & MVP

            when you scale a parent (like container), you also scale its children (like those boxes) even if the children are added after the parent is scaled.

            1 person found this helpful
            • 3. Re: Scaling problems with attachMovie
              IcarusFW Level 1

              Ned Murphy wrote:

              Is there something about the container that you need to set its size?  If you resize it, anything it contains is resized proportionally.  A container is usually best left alone, starting as an empty movieclip and filled with whatever it is deemed to contain.

               

              Hmmm, yes. At the moment, I have mouse position-based code that slides the container horizontally to reveal the rest of the items - the intention is to create a gallery "wall" using dynamic variables pulled from PHP, that you scroll left and right to view. I'm setting the size of the container in order to store all the image container instances side by side, as it means I only need to animate the container for the sliding effect, rather than loop through every generated instance.

               

              If there's an easier way of doing this, I'd love to know.

               

              kglad wrote:

              when you scale a parent (like container), you also scale its children (like those boxes) even if the children are added after the parent is scaled.

               

              No way of avoiding this? Pretty weird behaviour for Flash.

              • 4. Re: Scaling problems with attachMovie
                Ned Murphy Adobe Community Professional & MVP

                You normally just add content to an empty contiainer, there is no need to size it at all.  The content you place within it defines its dimensions.  You can still control its position (_x/_y) values as you desired, but there is no need to adjust its size.

                 

                There is nothing wierd about it, you just have to understand what the tool you are using does.

                • 5. Re: Scaling problems with attachMovie
                  IcarusFW Level 1

                  So, instead of creating a linked library element to use as a container with attachMovie, I use createEmptyMovieClip to create an empty clip and use that as my container instead?

                  What you're saying makes sense, I just need it translated into code I can use in my Flash projects.

                  • 6. Re: Scaling problems with attachMovie
                    Ned Murphy Adobe Community Professional & MVP

                    Yes, createEmptyMovieClip() will gain you the result you need for the container.  Then just control its position properties and leave its dimensions alone.