1 Reply Latest reply on Apr 10, 2012 12:10 PM by Ned Murphy

    Center align images flash

    kmott3d

      I have an actionscript that loads images for a slideshow. The images are different sizes and overlays in the slideshow top left justified.

      I would like to center the images.

      I am new to flash and I have very limited knowledge of actionscript.

      Below is the actionscript.  What do I need to add to it and where?

       

      Thanks

       

       

       

      pauseTime = 250;

      xmlImages = new XML();
      xmlImages.ignoreWhite = true;
      xmlImages.onLoad = loadImages;
      xmlImages.load("images.xml");

      function loadImages(loaded) {
      if (loaded) {
        xmlFirstChild = this.firstChild;
        imageFileName = [];
        totalImages = xmlFirstChild.childNodes[0].childNodes.length;
        for (i=0; i<totalImages; i++) {
         imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
        }
       
        randomImage();
      }
      }
      function randomImage() {
      if (loaded == filesize) {
        var ran = Math.round(Math.random() * (totalImages - 1));
        picture_mc.loadMovie(imageFileName[ran], 1);
        pause();
      }
      }
      function pause() {
      myInterval = setInterval(pause_slideshow, pauseTime);
      function pause_slideshow() {
        clearInterval(myInterval);
        randomImage();
      }
      }

        • 1. Re: Center align images flash
          Ned Murphy Adobe Community Professional & MVP

          What you need to do is use the MovieClipLoader class instead of the loadMovie method.  You need to know when the image has loaded before you can try to cetnter it, and the MovieClipLoader class allows for assigning a listener for that.  If you look up the MovieClipLoader.addListener method in the help documentation there is an example there that details how to use it.

           

          Once you have the image loaded you just need to do a little math to center it based on the width and height of the image as compared to the width and height of the intended viewing area... as in... img._x = (area._width - img._width)/2 , and similar for y using the height.