Hi there, i’ve found a script i’ve been trying to edit. My end result is i want to place pictures into the movieclip from the results of my PHP. The script currently loads its info from a flat xml file a list of image URLS. But i want to take the URLs from my php/mysql DB. The table in my sql table has this information:
ID, name, url1, url2, and price
So i use these codes:
<?php
define(DB_HOST, "localhost");
define(DB_USER, "username");
define(DB_PASSWORD, "password");
define(DB_DB, "dbname");
define(SHOW_MYSQL_ERRORS, true);
$link = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db = @mysql_select_db(DB_DB);
if(!$link && !$db){
echo "status=error&error=" . urlencode("error");
if(SHOW_MYSQL_ERRORS){
echo urlencode("
MySQL reported the following:
" . mysql_error());
}
exit();
}
?>
<?php
include_once("settings.inc.php");
//getPictures.php to retrieve pictures from database.
$query = "SELECT * FROM swatches ORDER BY id";
$result = @mysql_query($query);
if($result)
{
$i = 0;
while($cat = mysql_fetch_array($result))
{
echo "&id" . $i . "=" . $cat["id"];
echo "&name" . $i . "=" . $cat["name"];
echo "&url1" . $i . "=" . $cat["url1"];
echo "&url2" . $i . "=" . $cat["url2"];
echo "&price" . $i . "=" . $cat["price"];
$i++;
}
echo "&picCount=" . $i;
}
else
{
fail("Error", mysql_error());
}
?>
This is all working correctly, and so far i can connect fine from flash using this
_root.CurrentPage = 1;
function loadPictures()
{
myPictures = new LoadVars()
myPictures.load("getPictures.php")
myPictures.onLoad = function(success)
{
if(success)
{
for(i = 0; i < 10; i++)
{
//errors in here
}
for(i = 0; i < myPictures.picCount; i++)
{
_root["pic"+i].name = myPictures["picName" + i];
_root["pic"+i].price = myPictures["picPrice" + i];
loadMovie(myPictures["url1"+i], _root["pic"+i].imageHolder);
}
}
}
}
loadPictures();
stop();
but now i need to incorporate the above into the below code, so that i produce movieclips each with the different image thumbnail (url1) then hopefully i need to store the price url2 somewhere on each pciture as it is created, so i can try to add some otherthings when each thumbnail is clicked.
Here is the code. I just don’t understand how to use this as arrays…
// Import the transitions classes so you can add a fading effect when the images load to the Stage.
import mx.transitions.*;
// Set the starting X and Y positions for the gallery images.
_global.thisX = 30;
_global.thisY = 70;
/* Set static values for the Stage's width and height.
Using Stage.width and Stage.height within the code results in
strangely positioned full images when testing in the Flash environment
(but the problem doesn't exist when published to a SWF file). */
_global.stageWidth = 600;
_global.stageHeight = 400;
/* create a function which loops through the images in an array,
and creates new movie clips on the Stage. */
function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
// loop through each of the images in the gallery_array.
for (var i = 0; i<galleryLength; i++) {
/* create a movie clip instance which holds the image. We'll also set a variable,
thisMC, which is an alias to the movie clip instance. */
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
/* load the current image source into the new movie clip instance,
using the MovieClipLoader class. */
mcLoader_mcl.loadClip(gallery_array*.src, thisMC);
// attach the preloader symbol from the Library onto the Stage.
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
/* set the preloader's bar_mc's _xscale property to 0%
and set a default value in the progress bars text field. */
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
// set the _x and _y coordinates of the new movie clip.
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
// set the position of the image preloader.
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
// if you've displayed 5 columns of images, start a new row.
if ((i+1)%5 == 0) {
// reset the X and Y positions
_global.thisX = 20;
_global.thisY += 80;
} else {
_global.thisX += 80+20;
}
}
}
// define the MovieClipLoader instance and MovieClipLoader listener Object.
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
// while the content is preloading, modify the width of the progress bar.
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
// create a shortcut for the path to the preloader movie clip.
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
};
// when the onLoadInit event is thrown, you're free to position the instances
mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
/* set local variables for the target movie clip's width and height,
and the desired settings for the image stroke and border. */
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 2;
var marginWidth:Number = 8;
evt.scale = 20;
// draw a white rectangle with a black stroke around the images.
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.endFill();
};
loadPictures();
stop();
if someone could give me a little line how to change it from an array that would be amazing. Also if someone has an idea how i can add the name, url2 and price information from the sql DB into each thumnail as they are created… I would eventually like to make it so when clicked, the original image is loaded ontop of what theyre viewing, and they can close it again. then the final step for me will be to make a button for each thumbnail called (select this one), which will set a variable to the name of the pictures
Thanks so much for anyone who’s read this far and have helped!
best regards
Ukguy