Photo gallery with buttons and php.
I am relatively new to actions script, very new to as3, and brand new to php. I have tried very hard to figure all of this out via tutorials, studying the code, etc but now I'm running out of time to get this done so I need some help.
I am trying to make a photo gallery that functions as follows:
-the php gathers all of the filenames from a folder and returns it to flash
-an array of buttons is loaded onto the stage (one for each photo)
-flash then loads the first image into a movie clip.
-when the user clicks on button, image loads in the movie clip.
-i also plan to incorporate what might happen if the number of photos exceeds the number of buttons that can fit nicely on the stage, like an arrow to go to another set of buttons. I haven't tried coding this yet since I was just trying to get the thing to work in general first. If anyone has ideas about this, let me know.
Please don't make fun of me too much. I know it's probably a mess.
Thank you so much in advance for your help.
Here's the php:
<!--
Author: Adam Ehrheart
Site: http://adamehrheart.com
Blog: http://flashcamp.net
Date: 4.21.08
-->
<?php
# Use "." if the get_files.php file resides in the same directory as files being read
# Otherwise you can change the path to whatever you like
# eg:
# Same Directory:
# $path = ".";
#
# Other Directory
# $path = "products/images/"
$path = "Photography/";
# Choosing what directory to read
if ($handle = opendir($path)) {
# Temporary array to hold image files
$imageFiles = array();
# Creating loop and assigning current file to $file temp variable
while (false !== ($file = readdir($handle)))
{
# Checking wheter or not the file is invisible and starts with a "."
$fileCheck = substr($file, 0, 1);
# Checking to make sure the files is either a (jpg, JPG, png, PNG)
$fileType = substr($file, -3);
# Making sure file is not invisible
if($fileCheck != ".")
{
# Making sure file is readable and dynamically loadable by Flash
if($fileType == "jpg" || $fileType == "JPG" || $fileType == "png" || $fileType == "PNG")
{
# Adding File to the image array
if($path != "."){
array_push($imageFiles, $path . $file);
}else{
array_push($imageFiles, $file);
}
}
# Sorting the files alphabetically
sort($imageFiles);
}
}
# Creating XML File output to be read by Flash
echo "<?xml version=\"1.0\"?>\n";
# Root Node
echo "<image_list>";
# Creating child nodes for each image
foreach($imageFiles as $value)
{
# Pulling the Width and Height values for each file and adding them as attributes for the image node
list($width, $height) = getimagesize($value);
# Creating the image node
echo "<image width=\"$width\"" . " height=\"$height\">" . $value . "</image>";
}
echo "</image_list>";
# Closing the readdir function
closedir($handle);
}
And here's the as3:
//php photo section
import flash.events.Event;
import flash.net.*;
//load the php file
var myRequest:URLRequest = new URLRequest("Photography.php");
var myLoader:URLLoader = new URLLoader();
//define images variable as an xml file
var images:XML = new XML();
images.ignoreWhite = true;
images.addEventListener ('load', myLoader);
//define the images variable as an xml as the php file result
myRequest.data = images;
//outputting the filenames
function onLoaded(evt:Event):void {
trace("here we get the data back: "+myLoader.data);
}
//when the data is loaded, begin myRequest
myLoader.addEventListener(Event.COMPLETE, onLoaded);
myLoader.load(myRequest);
//array to call the images
var imageArray:Array //= NewArray();
var listLength:Number;
var il:XMLList = images.data //xml.images;
listLength=il.length();
var i:Number
var photo_btn:Array = new Array();
for (i = 0; i < listLength; i++); {
imageArray = il.pic //xml.images.pic;
{
if (photo_btn.mouseDown == true) {
img_loader.load(imageArray)
}
}
{
if (i == 0) {
photo_btn.y = 422.7;
photo_btn.x = 411.5
}
else if (i > 0 && i < 24); {
photo_btn.y = 422.7;
photo_btn.x = (photo_btn[i-1].x + 18.6);
}
{
if (i > 24 && i < listLength); {
photo_btn.y = 442.7;
photo_btn.x = (photo_btn[i-1].x + 18.6);
}
}
}
img_loader.load(imageArray[0]);
}