5 Replies Latest reply on Oct 31, 2007 10:31 AM by kglad

    loadmovie over prev loadmovie and positioning jpg

    Starlover_jacob Level 1
      Hello, a little question and i have the feeling i am very close.

      i use loadmovie to load an image into an movieclip.
      that movieclip goes to the position x and y of the movieclip - the loaded image width/2

      my problem is that when i load a new image the position is not correct.

      my code:
      ------------------------------------------------------------------------------------------ --------------------------
      function nextImage1()
      {
      if (p < total - 1)
      {
      ++p;
      if (loaded == filesize)
      {
      trace(p);
      trace("x van inst0"+litlimg_instance.ltlimgmc_instance0._x);
      trace("y van inst0"+litlimg_instance.ltlimgmc_instance0._y);
      litlimg_instance.ltlimgmc_instance0._alpha = 0;
      litlimg_instance.ltlimgmc_instance0.holder.loadMovie(image[p], 1);

      var maxWidth = 250;
      var maxHeight = 200;

      var myWidth = litlimg_instance.ltlimgmc_instance0._width;
      var myHeight = litlimg_instance.ltlimgmc_instance0._height;
      // Calculate percentage by which image will need to change to fit
      if (myWidth > maxWidth){
      var xscalePercent = (myWidth*100)/maxWidth;
      }
      if (myHeight > maxHeight){
      var yscalePercent = (myHeight*100)/maxHeight;
      }
      // Multiply both height and width by the bigger percentage
      if (xscalePercent>yscalePercent) {
      litlimg_instance.ltlimgmc_instance0._width /= (xscalePercent/100);
      litlimg_instance.ltlimgmc_instance0._height /= (xscalePercent/100);
      } else {
      litlimg_instance.ltlimgmc_instance0._width /= (yscalePercent/100);
      litlimg_instance.ltlimgmc_instance0._height /= (yscalePercent/100);
      }
      var test=litlimg_instance._x-(litlimg_instance.ltlimgmc_instance0._width/2);
      trace("width img:"+litlimg_instance.ltlimgmc_instance0._width);
      trace("width:2 :"+litlimg_instance.ltlimgmc_instance0._width/2);
      trace("x position must be:"+test);
      trace("x position is:"+litlimg_instance.ltlimgmc_instance0._x);
      trace("----------------------------------------------------");

      litlimg_instance.ltlimgmc_instance0._x=litlimg_instance._x-(litlimg_instance.ltlimgmc_ins tance0._width/2);
      litlimg_instance.ltlimgmc_instance0._y=litlimg_instance._y-(litlimg_instance.ltlimgmc_inst ance0._height/2);
      slideshow();
      } // end if
      } // end if
      } // End of the function


      function slideshow()
      {
      function pause_slideshow()
      {
      clearInterval(myInterval);
      if (p == total - 1)
      {
      p = 0;
      firstImage1();
      }
      else
      {
      nextImage1();
      } // end else if
      } // End of the function
      myInterval = setInterval(pause_slideshow, 4000);
      } // End of the function

      p = 0;
      ------------------------------------------------------------------------------------------ --------------------------

      what i do is i have an array with the image links.
      on a interval i load an image. and if p has reached the number of loaded images i start over again.

      i traced the following while testing a bunch of images:
      -------

      1
      x van inst0-125
      y van inst0-93.55
      width img:250
      width:2 :125
      x position must be:-125
      x position is:-125
      ----------------------------------------------------
      2
      x van inst0-125
      y van inst0-93.55
      width img:258.05
      width :2 :129.025
      x position must be:-129.025
      x position is:-125
      ----------------------------------------------------
      3
      x van inst0-129
      y van inst0-93.55
      width img:140.3
      width :2 :70.15
      x position must be:-70.15
      x position is:-129
      ----------------------------------------------------
      4
      x van inst0-70.15
      y van inst0-93.55
      width img:243.2
      width :2 :121.6
      x position must be:-121.6
      x position is:-70.15
      ----------------------------------------------------
      1
      x van inst0-125
      y van inst0-93.55
      width img:250
      width :2 :125
      x position must be:-125
      x position is:-125
      ----------------------------------------------------

      It looks like he takes the position of the prev image or something like that.

      Please some help here.

      Greetz. Jacob

      Ps: this was some code i posted.. i would like to know how you put it into such a nice code block on the forum so it becomes more readable.