8 Replies Latest reply on Oct 13, 2006 5:48 AM by injpix

    align external .swf

    gringito
      I have a main movie. There is a mc container called loader and couple of external animations called anima.swf. I dont know the anima.swf size (width, height), but I know it will always be smaller (width, height) than the loader.

      How to write an AS which would align my anima.swf inside the container loader

      1) to be on CENTER, MIDDLE
      2) to be on CENTER, TOP
      3) to be on CENTER, BOTTOM
      etc.

      thanks for any help
        • 1. Re: align external .swf
          Level 7
          Typically your container would be an empty clip. And it being 0 x 0 in size,
          there is no center, or top or bottom. Loaded movies come into the container
          at 0,0. If you want to align the loaded clip to the Stage, or to another
          clip, then your best bet is to use the MovieClipLoader class and its
          associated onLoadInit method to move the loaded clip once it's ready.

          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          http://www.adobe.com/communities/experts/


          • 2. Re: align external .swf
            friendDips
            Try this

            Each time when you are loading the new swf, you can set the x, y position of
            your mc-container loader.
            • 3. Re: align external .swf
              gringito Level 1
              the x,y position and the size of the container stays same all the time. I need to move the "content" - the external .swf ...
              • 4. Re: align external .swf
                friendDips Level 1
                Your loader movieclip being empty, it will show the content. Just you have to adjust the position accordingly. it won't show the position for empty movie. it will show for the content only.
                • 5. Re: align external .swf
                  injpix Level 3
                  Of course it’s possible to do this. What you would need to do is, load the SWF into a movieclip and when its fully loaded you can then retrieve its X Y properties. After you have those 2 values, just do some arithmetic to align it.

                  So I would recommend to load the SWF using the MovieClipLoader.
                  http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context= LiveDocs_Parts&file=00002543.html

                  …This link goes to its onLoadComplete (). The code on the bottom of this page uses loadClip() to load the content and the onLoadInit is invoked when the SWF is fully loaded and able to access its properties. Ahh…this example shows exactly what you need! Notice that the onLoadComplete() returns 0 for the loaded _width. You must use the onLoadInit()! This is mentioned in the 3rd paragraph. So once you get a value from this function, do some division to find its center. Let’s say that the SWF has a value of 200 for its _width. Just divide that by 2 (200/2) and that will give you the value to the center vertical axis. Do the same for the _height and that will give you the center horizontal axis. Then with those values, assign the content using _x and _y properties.
                  • 6. Re: align external .swf
                    gringito Level 1
                    uuuuy ... thanks a lot ... but - well - I am beginner. this is beyond my brain capacity :))) ... it is too compicated for me to understand. may I ask you to be more SIMPLE? ...
                    I have the container already on the scene, fixed size 200x200 px.
                    I load the the external .swf like: loadMovie(nameofthefile, "loader");

                    what shall come next?
                    • 7. Re: align external .swf
                      gringito Level 1
                      I managed the easy part of the problem. I load my .swf like:

                      var mcLoader:MovieClipLoader = new MovieClipLoader();
                      mcLoader.addListener(loadListener);
                      mcLoader.loadClip("anima.swf", "loader");

                      and now I need to add the Listener and get the _width value of "anima.swf". but I dont know how ...

                      this is the FLASH HELP but how to use it ...

                      var loadListener:Object = new Object();
                      loadListener.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number):Void {
                      trace(">> loadListener.onLoadComplete()");
                      trace(">> =============================");
                      trace(">> target_mc._width: " + target_mc._width); // 0
                      trace(">> httpStatus: " + httpStatus);
                      }
                      loadListener.onLoadInit = function(target_mc:MovieClip):Void {
                      trace(">> loadListener.onLoadInit()");
                      trace(">> =============================");
                      trace(">> target_mc._width: " + target_mc._width); // 315
                      }

                      the alignment (CENTER, MIDDLE) might work like:

                      target_mc._y = (loader._width - target_mc._width)/2;
                      target_mc._x = (loader._height - target_mc._height)/2;

                      but how to put all this together ? ... any help, uff?




                      • 8. Re: align external .swf
                        injpix Level 3
                        The code below will load a SWF file named “ball” and when the onLoadInit is invoked it will invoke a function called alignMovieClip. It is here where you need to do some work.
                        You want 3 possible alignment settings for this project of yours, center/top, center/middle and center/bottom. Currently the code only has one alignment setting coded in this alignMovieClip function, center/middle. The first line of code is commented out. You can make 2 other lines of code that are similar for the other 2 alignment settings. And then something or someone will make one of those variables true. The conditional statement that is commented out in the alignMovieClip function will choose the correct alignment setting by the variable that is true.