7 Replies Latest reply on Jul 5, 2006 5:59 AM by byenary

    Center dynamicly loaded jpg

    byenary
      Hello im loading dynamicly a bunch of jpg's
      When they are same size of stage its fine but when they do not have the width or hight, they end up in lef top corner...
      Can i get dimensions of jpg before doing this
      loadMovie(pathToPics+arrFilename[teller], mcPlayer.mcFotoList);
      If there is a way to get the dimensions of the jpg i could alter de placeholder...

      Grts
        • 1. Re: Center dynamicly loaded jpg
          Level 7
          Hi!

          You get it after it is fully loaded. So what you would normally do is hide
          the MC you are loading into (for example setting _alpha to 0) and then after
          it is fully loaded, you get the _width and _height from that MC. Then resize
          and position it before making it visible (for example with _alpha = 100).

          /Jensen/


          "byenary" <webforumsuser@macromedia.com> wrote in message
          news:e7th8v$elk$1@forums.macromedia.com...
          > Hello im loading dynamicly a bunch of jpg's
          > When they are same size of stage its fine but when they do not have the
          > width
          > or hight, they end up in lef top corner...
          > Can i get dimensions of jpg before doing this
          > loadMovie(pathToPics+arrFilename[teller], mcPlayer.mcFotoList);
          > If there is a way to get the dimensions of the jpg i could alter de
          > placeholder...
          >
          > Grts
          >


          • 2. Re: Center dynamicly loaded jpg
            danieldear
            use loader (component) to load ur pics so that u can scale it and set it to its position
            • 3. Re: Center dynamicly loaded jpg
              JBOY_PLUS
              Like Jensen said; hide the content from the viewer until it's fully loaded, perhaps adding a preloader to each of ur files. If ur not allready familiar with the MovieClipLoader u should try lookíng at it. It gives u full control over the different stages of the loading process. the start, the progress, when its fully loaded and if u load SWFs when the actions in frame one is executet...

              Tjeck out this tutorial:
              http://www.actionscript.org/tutorials/intermediate/MovieClipLoader_in_Flash_MX_2004/index. shtml
              • 4. Re: Center dynamicly loaded jpg
                byenary Level 1
                Hello, ive been trying with the mcloader,
                and it all went fine, but now ive got a problem, I made a piece of code wich takes targetMc width and height, and based on that to set x an y for the targetMC. If targetMC (the picture) is bigger than Stage i rescale it wich goes fine as well, but when ive done a rescale of targetMc the next picture goes wrong, ill explain with code
                So i do this
                myMCL.loadClip(pathToPics+arrFilename[teller], "_level0.myMC1");
                This gets called by a timer depending on an xmlfile ...
                arrFilename contains pic1.jpg, pic2.jpg , pic1.jpg
                it is processed by this code

                myMCL.onLoadInit = function (targetMC)
                {
                trace ("Current targetMC dimensions");
                trace ("Target Width = "+ targetMC._width);
                trace ("Target Height = "+ targetMC._height);
                var scaleratio;
                if (targetMC._width > Stage.width){
                trace("resize width");
                scaleratio = targetMC._width / Stage.width;
                trace("scaleratio= "+ scaleratio);
                targetMC._width = Stage.width;
                targetMC._height = targetMC._height/scaleratio;
                }
                trace("tussenin");
                trace ("Target Width = "+ targetMC._width);
                trace ("Target Height = "+ targetMC._height);
                if (targetMC._height > Stage.height){
                trace("resize height");
                trace ("Target Height = "+ targetMC._height +"/ stageheight " + Stage.height );
                scaleratio = targetMC._height/ Stage.height;
                trace("scaleratio= "+ scaleratio);
                targetMC._height = Stage.height;
                targetMC._width = targetMC._width/scaleratio;
                }
                targetMC._x = (Stage.width-targetMC._width)/2;
                targetMC._y = (Stage.height-targetMC._height)/2;
                trace ("Rescaled targetMC dimensions");
                trace ("Target Width = "+ targetMC._width);
                trace ("Target Height = "+ targetMC._height);
                }

                the trace result :

                Current targetMC dimensions
                Target Width = 1023
                Target Height = 682
                tussenin
                Target Width = 1023
                Target Height = 682
                Rescaled targetMC dimensions
                Target Width = 1023
                Target Height = 682
                1
                2
                3
                4
                5
                Current targetMC dimensions
                Target Width = 2832
                Target Height = 2128
                resize width
                scaleratio= 2.765625
                tussenin
                Target Width = 1023.95
                Target Height = 769.45
                resize height
                Target Height = 769.45/ stageheight 768
                scaleratio= 1.00188802083333
                Rescaled targetMC dimensions
                Target Width = 1022
                Target Height = 768
                7
                8
                9
                10
                Current targetMC dimensions
                Target Width = 369.15
                Target Height = 246.15
                tussenin
                Target Width = 369.15
                Target Height = 246.15
                Rescaled targetMC dimensions
                Target Width = 369.15
                Target Height = 246.15


                So problem is : when loading pic1.jpg the first times it gets it dimensions right : 1023 * 682 : ok
                when loading pic2 which is to big it gets scaled wich goes fine : ok
                when loading pic1 for second time things go wrong cause it has dimensions
                369.15* 246.15
                It has something to do with changing the targetMC properties, i might need to reset them after each pic or something
                Any ideas, thanks for helping
                • 5. Re: Center dynamicly loaded jpg
                  Level 7
                  Hi!

                  Maybe it helps to create the MC dynamically before loading into it. Then you
                  can remove it before creating it, so first time through, you remove
                  something that is not there, then created it, load, then on next one you
                  remove it and then create it again.

                  Check out createEmptyMovieClip.

                  /Jensen/

                  "byenary" <webforumsuser@macromedia.com> wrote in message
                  news:e8fsuh$8fc$1@forums.macromedia.com...
                  > Hello, ive been trying with the mcloader,
                  > and it all went fine, but now ive got a problem, I made a piece of code
                  > wich
                  > takes targetMc width and height, and based on that to set x an y for the
                  > targetMC. If targetMC (the picture) is bigger than Stage i rescale it wich
                  > goes
                  > fine as well, but when ive done a rescale of targetMc the next picture
                  > goes
                  > wrong, ill explain with code
                  > So i do this
                  > myMCL.loadClip(pathToPics+arrFilename[teller], "_level0.myMC1");
                  > This gets called by a timer depending on an xmlfile ...
                  > arrFilename contains pic1.jpg, pic2.jpg , pic1.jpg
                  > it is processed by this code
                  >
                  > myMCL.onLoadInit = function (targetMC)
                  > {
                  > trace ("Current targetMC dimensions");
                  > trace ("Target Width = "+ targetMC._width);
                  > trace ("Target Height = "+ targetMC._height);
                  > var scaleratio;
                  > if (targetMC._width > Stage.width){
                  > trace("resize width");
                  > scaleratio = targetMC._width / Stage.width;
                  > trace("scaleratio= "+ scaleratio);
                  > targetMC._width = Stage.width;
                  > targetMC._height = targetMC._height/scaleratio;
                  > }
                  > trace("tussenin");
                  > trace ("Target Width = "+ targetMC._width);
                  > trace ("Target Height = "+ targetMC._height);
                  > if (targetMC._height > Stage.height){
                  > trace("resize height");
                  > trace ("Target Height = "+ targetMC._height +"/ stageheight " +
                  > Stage.height );
                  > scaleratio = targetMC._height/ Stage.height;
                  > trace("scaleratio= "+ scaleratio);
                  > targetMC._height = Stage.height;
                  > targetMC._width = targetMC._width/scaleratio;
                  > }
                  > targetMC._x = (Stage.width-targetMC._width)/2;
                  > targetMC._y = (Stage.height-targetMC._height)/2;
                  > trace ("Rescaled targetMC dimensions");
                  > trace ("Target Width = "+ targetMC._width);
                  > trace ("Target Height = "+ targetMC._height);
                  > }
                  >
                  > the trace result :
                  >
                  > Current targetMC dimensions
                  > Target Width = 1023
                  > Target Height = 682
                  > tussenin
                  > Target Width = 1023
                  > Target Height = 682
                  > Rescaled targetMC dimensions
                  > Target Width = 1023
                  > Target Height = 682
                  > 1
                  > 2
                  > 3
                  > 4
                  > 5
                  > Current targetMC dimensions
                  > Target Width = 2832
                  > Target Height = 2128
                  > resize width
                  > scaleratio= 2.765625
                  > tussenin
                  > Target Width = 1023.95
                  > Target Height = 769.45
                  > resize height
                  > Target Height = 769.45/ stageheight 768
                  > scaleratio= 1.00188802083333
                  > Rescaled targetMC dimensions
                  > Target Width = 1022
                  > Target Height = 768
                  > 7
                  > 8
                  > 9
                  > 10
                  > Current targetMC dimensions
                  > Target Width = 369.15
                  > Target Height = 246.15
                  > tussenin
                  > Target Width = 369.15
                  > Target Height = 246.15
                  > Rescaled targetMC dimensions
                  > Target Width = 369.15
                  > Target Height = 246.15
                  >
                  >
                  > So problem is : when loading pic1.jpg the first times it gets it
                  > dimensions
                  > right : 1023 * 682 : ok
                  > when loading pic2 which is to big it gets scaled wich goes fine : ok
                  > when loading pic1 for second time things go wrong cause it has dimensions
                  > 369.15* 246.15
                  > It has something to do with changing the targetMC properties, i might need
                  > to
                  > reset them after each pic or something
                  > Any ideas, thanks for helping
                  >


                  • 6. Re: Center dynamicly loaded jpg
                    Rothrock Level 5
                    When you change the _width and _height properties, Flash automatically adjust the _xscale and _yscale properties to the correct values. Those values are being inherited by the next clip that is being loaded.

                    So the easiest way I've found is to set myClip._xscale=myClip._yscale=100 just after the clip loads. Then you can be sure that the size you are reading is the real size.
                    • 7. Re: Center dynamicly loaded jpg
                      byenary Level 1
                      That is correct !
                      Adding this made it work as it should ... THX a lot !

                      myMCL.onLoadComplete = function (targetMC)
                      {
                      targetMC._xscale = 100;
                      targetMC._yscale = 100;

                      }