Skip to main content
Inspiring
October 29, 2007
Question

loadmovie over prev loadmovie and positioning jpg

  • October 29, 2007
  • 4 replies
  • 359 views
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

, 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_instance0._width/2);
litlimg_instance.ltlimgmc_instance0._y=litlimg_instance._y-(litlimg_instance.ltlimgmc_instance0._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.

This topic has been closed for replies.

4 replies

kglad
Community Expert
Community Expert
October 31, 2007
i can see what your problem is, i explained what your problem is and i mentioned a solution: assign your target movieclip's position AFTER loading is complete.

if you want me to re-write your code, you'll need to hire me. that wouldn't cost much, but you if you do this yourself you'll learn more. try to do what i suggested and post your revised code, if you're still having a problem or go to kglad.com, click contact and send an email about hiring me.
kglad
Community Expert
Community Expert
October 31, 2007
you think that's what you did?? why would you think that?

do you see anything about your target's width and height within your if-statement?

do you see any code, trying to, use your target's width and height outside of your if-statement?

and when posting code to this forum, format your code and use the attach code option. that will make your code much easier to read.
Inspiring
October 31, 2007
Hi there
sorry for the long pieces of code.
I will use the attach code button next time.

Here a url to my project file so you can see how it works.
http://members.lycos.nl/jacobhingst/troep/photoslider/

I hope you see what my problem is.
Greetz, jacob
Inspiring
October 31, 2007
I think thats what i did..

if (loaded == filesize)
{
trace(p);
trace("x van inst0"+l
etc.



this.onEnterFrame = function ()
{
filesize = litlimg_instance.ltlimgmc_instance0.holder.getBytesTotal();
loaded = litlimg_instance.ltlimgmc_instance0.holder.getBytesLoaded();
// preloader._visible = true;
if (loaded != filesize)
{
// preloader.preload_bar._xscale = 100 * loaded / filesize;
}
else
{
preloader._visible = false;
if (litlimg_instance.ltlimgmc_instance0._alpha < 100)
{
litlimg_instance.ltlimgmc_instance0._alpha = litlimg_instance.ltlimgmc_instance0._alpha + 10;
} // end if
} // end else if
};

And still its going wrong.

Greetz, jacob
kglad
Community Expert
Community Expert
October 30, 2007
you must wait until loading is complete to access the _width and _height of the load target.