Jpeg preloader form php [flash mx]

Hello everyone,
I tried to do a search but I couldn’t find anything that addressed this.

I am using a premade gallery app… ImageVue Demo

My client does not want images to show up bigger than the movie clip, thus needing to scroll. So I modified the code in PHP and changed the loadmovie action to imitate the thumbnail loader. Only now the loading progress is dead. Everything loads fine, just the loader dies.

I can’t remember the link but I read something about a problem loading dynamic xml into a movie so I tried that solution, buffering the output. Same result. If I just change the loadmovie back and remove the php file everything works fine, is there a solution to this?

Oh yeah, if I load the image just by typing in the url, it works fine, like this, only not the thumb… direct image

Code follows…

load call…
[AS]loadMovie((“getfile.php?img=”+_parent.prepath+_parent.file + “&size=default”), _parent.mytarget);[/AS]

loader code (kinda long, I’m not sure if I should strip anything out)…
[AS]onClipEvent (enterFrame) {
myload = _parent.mytarget.getBytesLoaded();
mytotal = _parent.mytarget.getBytesTotal();
mypercent = Math.round((myload/mytotal)*100);
bar._xscale = mypercent;
percent = mypercent+" %";
if ((myload == mytotal) and (myload>1000) and (_parent.mytarget._width>0)) {
//new write filename
_parent.nutopText = "image “+(_parent.image+1)+” - "+_parent.file;
_parent.testhead.text = _parent.nutopText;
_parent.testlength = _parent.testhead.textWidth;
_parent.thumbnailtoggler._visible = 1;
if (_parent.mytarget._width<=640) {
_parent.wsmall = 1;
_parent.mytarget._x = -(_parent.mytarget._width-640)/2+31;
} else {
_parent.mytarget._x = 31;
_parent.wsmall = 0;
if (_parent.mytarget._height<=360) {
_parent.hsmall = 1;
_parent.mytarget._y = -(_parent.mytarget._height-360)/2+39;
} else {
_parent.mytarget._y = 39;
_parent.hsmall = 0;
_parent.tsmall = _parent.hsmall+_parent.wsmall;
_parent.desc = _parent._parent.image.firstChild.childNodes[_parent.image].firstChild.nodeValue;
_parent.thumbfield = _parent._parent._parent.thumbnailofftext;
_parent.thumbindex = 0;
_parent.filedisplay = _parent.file.toUpperCase();
_parent.display = “image “+(_parent.image+1)+”/”+_parent._parent.imagearray.length;
_parent.multibuttons.multi[“clip”+_parent.image]._alpha = 50;

and the php file…

if (isset($_GET['size'])) { $size=$_GET['size']; }
$path = substr($img, 0, strrpos($img, '/'));
$file = substr($img, strrpos($img, '/') + 1);

$tnpath = $path . '/tn_' . $file;
$defPath = $path . '/def_' . $file;

if (@file_exists($defPath)) {
	    Header("Content-type: image/jpeg");
	} elseif (!file_exists($img)) {
	    die("Image doesn't exist");
	} else {
	    if (function_exists("imagecreatefromjpeg") and function_exists("imagecreatetruecolor")) {
	        $orig_image = imagecreatefromjpeg($img);
	        $orig_x = imagesx($orig_image);
	        $orig_y = imagesy($orig_image);
			if ($orig_y > 344) {
				$x = round($orig_x / ($orig_y / 344));
	            $y = 344;
				$def_image = imagecreatetruecolor($x, $y);
		        Imagecopyresampled($def_image, $orig_image, 0, 0, 0, 0, $x, $y, $orig_x, $orig_y);	        
				Header("Content-type: image/jpeg");
		        imageJPEG($def_image, '', 100);
				@imageJPEG($def_image, $defPath, 100);
		        imagedestroy ($def_image);
		        imagedestroy ($orig_image);
			} else {
				Header("Content-type: image/jpeg");
			    readfile($path . '/' . $file);
	    } else {
	        header("Content-type: image/jpeg");
	        readfile ('thumb.jpg');

The big problem with testing is, since it’s using a web server, and the AS isn’t written for it, trying to test the movie just doesn’t load the images and menu cause it can’t do the php calls.

I really need help with this one, please… :slight_smile: thanks.

Just a quick update before I go tackle something else for a while…

I set up a dummy text box just to pass the getBytesLoaded, etc. to. IT came back as non-existent basically. I guess this is exactly what I need to fix…

getbytesloaded - getsbytestotal = percent
0 - -1 = 0%
0 - -1 = 0%
0 - -1 = 0%
0 - -1 = 0%
0 - -1 = 0%
0 - -1 = 0%
16331 - 0 = Infinity%
48158 - 0 = Infinity%
48158 - 48158 = 100%

I hope someone knows how to fix this… :slight_smile: thanks again

install a local server ( ) so you can test your php,
post in the server-side forum for these questions,
do you still want me/someone to look at this or not…?

Thanks eyezberg,
Actually, I already have PHP, plus a bunch of other stuff installed, the problem was that the code I’m using (not originally mine) wasn’t written for this type of thing. I could modify it to perform things correctly, (pretty easily obviously) but as I stated above, I opted to just have it spit out info into a text box on the actual web page.

That aside, it’s irrelevent. I tweaked the getfile.php page and went over it to figure out why it was giving me errors/not caching correctly. I found I needed to place the header command in a different place. Down at the bottom. Everything works perfectly now.

I figured it out through the help of the Funciton blog. They used a similar thing for XML, and I just screwed up in coding the PHP. I wasn’t sure this was a server side problem when I first posted it.

Hopefully it’ll help others, since I couldn’t find any info on it around here.

Here’s the very bottom section of the updated PHP code…

	        header("Content-type: image/jpeg");
	        imageJPEG($sm_image, '', 95);
			@imageJPEG($sm_image, $tnpath, 95);
	        imagedestroy ($sm_image);
	        imagedestroy ($orig_image);
	    } else {
	        header("Content-type: image/jpeg");
	        readfile ('thumb.jpg');
$buffersize = ob_get_length();
header("Content-Length: $buffersize");

Just don’t forget the ob_start(); code at the top of the page…

Thanks everyone. :nerd:

thanks for updating, and posting the fix, I hate it when people don’t do that.