4 Replies Latest reply on Dec 18, 2007 12:02 PM by kglad

    resizing the images

    jlackyashdya
      hi,
      i want to resize and centering external images.

      i have done with centering the images.

      but how to do resizing.....here is my code....

      // code for centering images starts

      //Define center coordinates
      var centerX:Number = _root.emptymc_mc.imagemc_mc._width / 2;
      var centerY:Number = _root.emptymc_mc.imagemc_mc._height / 2;

      var movieClipLoader:MovieClipLoader = new MovieClipLoader();
      var loaderListener:Object = new Object();

      //Use the onLoadInit function to get the loaded images proportions
      loaderListener.onLoadInit = function(target:MovieClip) {

      trace(target._width + " x " + target._height)

      target._parent._x = centerX - target._width / 2;
      target._parent._y = centerY - target._height / 2;
      }
      // end resizing and centerring code

      // now loading images into movie clip loader

      movieClipLoader.addListener(loaderListener);
      var movieClipHolder:MovieClip = _root.emptymc_mc.imagemc_mc.createEmptyMovieClip(" container", getNextHighestDepth());

      var movieClipLoaderTarget:MovieClip = movieClipHolder.createEmptyMovieClip("loader", 1);

      //Load an image to the target
      movieClipLoader.loadClip(_parent._parent.thumbs.fi rstChild.childNodes[2].childNodes .childNodes[0].nodeValue, movieClipLoaderTarget);

      // end


      now how to resize the images???
        • 1. Re: resizing the images
          kglad Adobe Community Professional & MVP
          adjust their _width and _height in your onLoadInit() method, if you want to resize them as soon as they're loaded.

          place your centering code after your resize code.
          • 2. Re: resizing the images
            jlackyashdya Level 1
            Thanks for the reply...

            now its resizing and centering the images well but not according to the aspect ratio.

            see... i have one mc called imagemc_mc in which i want to load the images.

            so first i grab the width and height of the imagemc_mc in a varibale.

            var imgwidth = _root.emptymc_mc.imagemc_mc._width;
            var imgheight = _root.emptymc_mc.imagemc_mc._height;

            and then in onLoadInit() method first its check the width and height of the target and is it is greater than imagemc_mc then it resize the image to the imagemc_mc 's width and height.


            if(target._width > imgwidth && target._height > imgheight)
            {
            target._width = imgwidth;
            target._height = imgheight;
            }
            else
            {
            target._parent._x = centerX - target._width / 2;
            target._parent._y = centerY - target._height / 2;
            }

            target._parent._x = centerX - target._width / 2;
            target._parent._y = centerY - target._height / 2;

            }

            its working ....but if image is greater than imagemc_mc then the image is squeezing ....it is not according to the aspect ratio.

            please reply..............

            thanks a looooooooot



            • 3. Re: resizing the images
              BSpero Level 1
              Jlack,
              What size is imagemc_mc before you load the clip into it? If its dimensions are square, then that is what you are changing your loaded image to, since you check the size before you load it. It would probably be best to figure out by what percentage you need to shrink your loaded clip, and then multiply that by the height and width.
              • 4. Re: resizing the images
                kglad Adobe Community Professional & MVP
                you wouldn't expect your target to resize with its native ratio from the code you're using.

                is that what you're trying to do? ie, resize so your target's width is less than or equal to imgwidth and its height is less than or equal to imgheight while maintaining target's orginal width/height ratio?