nyghtrunner
07-18-2007, 10:16 PM
Hey all,
So I am having a problem creating what basically amounts to a dynamic slideshow. I'll try to be as detailed as possible, so you can see what I am talking about. First, I have a PHP file that is called to generate an XML file that contains paths and image size info for a series of images on a server. There's more to this, but it's all comparison data to make sure I don't get anything I don't want in the XML. This part is working. It returns everything I need, loads into flash without any problems, and displays the images.
So I moved on to step 2. The problem here is that I need to have PHP normalize the sizes of the images to be displayed. I thought maybe the best way to do this would be to point it to a new PHP page every time a new image needs to load, using the POST method and sendAndLoad. So I got online and found a tut that kind of looked like it would do what I need it to do... But something is very broken.
So here's hoping that the good old AS.org forum will not fail me, and that someone out there might be able to help me with my problem. :)
I'm posting code for you to look at and see if you might be able to figure out what's wrong with it.
First the actionscript...
_global.fanArt = this;
fanArt.createEmptyMovieClip("artHolder_mc", 100);
var myNum = 0;
fanArt.createEmptyMovieClip("buttonHolder_mc",101);
fanArt.buttonHolder_mc.attachMovie("button_mc","left_mc",1,{_x:457,_y:561});
fanArt.buttonHolder_mc.attachMovie("button_mc","right_mc",2,{_x:610,_y:561});
fanArt.buttonHolder_mc.right_mc.onRelease = function() {
if (myNum <= subArt.length) {
myNum++;
} else if (myNum == subArt.length) {
myNum = 0;
}
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
fanArt.buttonHolder_mc.left_mc.onRelease = function() {
if (myNum > 0) {
myNum--;
} else if (myNum == 0) {
myNum = subArt.length-1;
}
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
subArt = [];
function loadXML(loaded) {
if (loaded) {
//trace("loaded");
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
//trace(total);
for (i=0; i<total; i++) {
subArt[i] = [];
for (j=0; j<xmlNode.childNodes[i].childNodes.length; j++) {
subArt[i][j] = xmlNode.childNodes[i].childNodes[j].firstChild.nodeValue;
}
}
init();
} else {
content = "file not loaded!";
}
}
xmlDataStaff = new XML();
xmlDataStaff.ignoreWhite = true;
xmlDataStaff.onLoad = loadXML;
xmlDataStaff.load("http://www.edgarandellen.com.dev/imageSize.php");
function init() {
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
And the PHP...
<?php
// Incoming data via Post
$imageName = $_POST['imageName'];
$imageSizeX = $_POST['imageSizeX'];
$imageSizeY = $_POST['imageSizeY'];
$maxX = 120;
$maxY = 112;
$image = open_image($imageName);
if ($image === false) {
die('Unable to open image');
}
$oldX = $imageSizeX;
$oldY = $imageSizeY;
function open_image($file) {
// Get extension
$extension = strrchr($file, '.');
$extension = strtolower($extension);
switch($extension) {
case '.jpg':
case '.jpeg':
$im = @imagecreatefromjpeg($file);
break;
case '.gif':
$im = @imagecreatefromgif($file);
break;
// ... etc
default:
$im = false;
break;
}
return $im;
}
header("Content-type: image/jpeg");
if ($oldX > $oldY) {
$percent = ($maxX/$oldX);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$ newX,$newY,$oldX,$oldY);
} else {
$percent = ($maxY/$oldY);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$ newX,$newY,$oldX,$oldY);
}
$newImage = imagejpeg($image_resized);
die();
?>
So feel free to take a look, and see if you might be able to spot something somewhere that I am doing wrong. I have been using flash and as2 for a few years now, but am still pretty noob with PHP and SQL (only my 3rd week!), so I'm pretty sure that most of the AS will work, with the exception of the sendAndLoad Method I'm using (not sure I have the link back named correctly in either the AS or the PHP)...
Any help, as always, is appreciated! :)
Stephen
So I am having a problem creating what basically amounts to a dynamic slideshow. I'll try to be as detailed as possible, so you can see what I am talking about. First, I have a PHP file that is called to generate an XML file that contains paths and image size info for a series of images on a server. There's more to this, but it's all comparison data to make sure I don't get anything I don't want in the XML. This part is working. It returns everything I need, loads into flash without any problems, and displays the images.
So I moved on to step 2. The problem here is that I need to have PHP normalize the sizes of the images to be displayed. I thought maybe the best way to do this would be to point it to a new PHP page every time a new image needs to load, using the POST method and sendAndLoad. So I got online and found a tut that kind of looked like it would do what I need it to do... But something is very broken.
So here's hoping that the good old AS.org forum will not fail me, and that someone out there might be able to help me with my problem. :)
I'm posting code for you to look at and see if you might be able to figure out what's wrong with it.
First the actionscript...
_global.fanArt = this;
fanArt.createEmptyMovieClip("artHolder_mc", 100);
var myNum = 0;
fanArt.createEmptyMovieClip("buttonHolder_mc",101);
fanArt.buttonHolder_mc.attachMovie("button_mc","left_mc",1,{_x:457,_y:561});
fanArt.buttonHolder_mc.attachMovie("button_mc","right_mc",2,{_x:610,_y:561});
fanArt.buttonHolder_mc.right_mc.onRelease = function() {
if (myNum <= subArt.length) {
myNum++;
} else if (myNum == subArt.length) {
myNum = 0;
}
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
fanArt.buttonHolder_mc.left_mc.onRelease = function() {
if (myNum > 0) {
myNum--;
} else if (myNum == 0) {
myNum = subArt.length-1;
}
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
subArt = [];
function loadXML(loaded) {
if (loaded) {
//trace("loaded");
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
//trace(total);
for (i=0; i<total; i++) {
subArt[i] = [];
for (j=0; j<xmlNode.childNodes[i].childNodes.length; j++) {
subArt[i][j] = xmlNode.childNodes[i].childNodes[j].firstChild.nodeValue;
}
}
init();
} else {
content = "file not loaded!";
}
}
xmlDataStaff = new XML();
xmlDataStaff.ignoreWhite = true;
xmlDataStaff.onLoad = loadXML;
xmlDataStaff.load("http://www.edgarandellen.com.dev/imageSize.php");
function init() {
var imageName = subArt[myNum][0];
var imageWidth = subArt[myNum][1];
var imageHeight = subArt[myNum][2];
var sendImage = new LoadVars();
sendImage.imageName = imageName;
sendImage.imageSizeX = imageWidth;
sendImage.imageSizeY = imageHeight;
var recieveImage = new LoadVars();
recieveImage.onLoad = function() {
fanArt.artHolder_mc.loadMovie(newImage,fanArt.artH older_mc);
}
sendImage.sendAndLoad("resizer.php", recievePoster, "POST");
sendImage.send("resizer.php","_blank","POST");
//for debugging purposes, you can use the "send" function in an _blank to act as a trace here.
fanArt.myText=subArt[myNum][0];
}
And the PHP...
<?php
// Incoming data via Post
$imageName = $_POST['imageName'];
$imageSizeX = $_POST['imageSizeX'];
$imageSizeY = $_POST['imageSizeY'];
$maxX = 120;
$maxY = 112;
$image = open_image($imageName);
if ($image === false) {
die('Unable to open image');
}
$oldX = $imageSizeX;
$oldY = $imageSizeY;
function open_image($file) {
// Get extension
$extension = strrchr($file, '.');
$extension = strtolower($extension);
switch($extension) {
case '.jpg':
case '.jpeg':
$im = @imagecreatefromjpeg($file);
break;
case '.gif':
$im = @imagecreatefromgif($file);
break;
// ... etc
default:
$im = false;
break;
}
return $im;
}
header("Content-type: image/jpeg");
if ($oldX > $oldY) {
$percent = ($maxX/$oldX);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$ newX,$newY,$oldX,$oldY);
} else {
$percent = ($maxY/$oldY);
$newX = $oldX*$percent;
$newY = $oldY*$percent;
$image_resized = imagecreatetruecolor($newX,$newY);
$newImage = imagecopyresampled($image_resized,$image,0,0,0,0,$ newX,$newY,$oldX,$oldY);
}
$newImage = imagejpeg($image_resized);
die();
?>
So feel free to take a look, and see if you might be able to spot something somewhere that I am doing wrong. I have been using flash and as2 for a few years now, but am still pretty noob with PHP and SQL (only my 3rd week!), so I'm pretty sure that most of the AS will work, with the exception of the sendAndLoad Method I'm using (not sure I have the link back named correctly in either the AS or the PHP)...
Any help, as always, is appreciated! :)
Stephen