Hi, :kommie:
Hope someone can advise me whats gone wrong…
I’ve built a fla file which use PHP (Flash remote) to load random jpgs from a directory into a movie clip. All tutorials i’ve followed shows you loading one jpg per page…i’m loading 9. Orginally when loading any images from my harddrive the movie clip locations remained the same x0,y0 x320,y0 x640,y0 etc. (if you see the swf there is a grid, and a clip loaded into each rectangle) Now when i load my jpgs via PHP all my movie clip locations seem to reset back to Co ords 0,0.
This is my flash AS. Which is repeated 9 times for the nine movie clips. MC instances are Key1, Key 2, Key3 etc…obviously this is key1
[AS]#include “NetServices.as”
#include “NetDebug.as”
///////////////////////////////////////////
//Directory where the service look for images
//Remember: should be inside services folder
///////////////////////////////////////////
directory = “pics”
///////////////////////////////////////////
//Requests Handlers
///////////////////////////////////////////
getImage_Result = function(image){
//image could be the name of an image or an error message
message.text = image
key1.loadMovie(“services/”+directory+"/"+image)
}
//////////////////////////////////////////
// Connection to service
//////////////////////////////////////////
var conn = NetServices.createGatewayConnection(“gateway.php”);
// Specify the service you want to use. There has to be a file called ‘randomImage.php’
// in your services directory.
var myService = conn.getService(“randomImage”, this);
myService.getImage(directory)
//////////////////////////////////////
//Components handlers
///////////////////////////////////////
function refresh(){
//Call the service
myService.getImage(directory)
}
stop()[/AS]
All this action scripts use the same php files, the main random image php script being …
<?php
class randomImage
{
function randomImage()
{
$this->methodTable = array(
"getImage" => array(
"description" => "Returns a random jpg file in a given directory.",
"access" => "remote",
"arguments" => array ("directory")
)
);
}
function getImage($directory) {
// open up file directory.
if (is_dir($directory)) {
if ($dh = opendir($directory)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {
// If jpg file, add to an array.
if (substr($file, strrpos($file, "."))==".jpg") $temp[] = $file;
}
}
closedir($dh);
// return a random element of this array
return $temp[mt_rand(0, sizeof($temp)-1)];
} else {
// return an error if the directory could not be opened.
return 'There was an error when trying to open the specified directory ('.$directory.') .';
}
} else {
// adds some error handling if the directory can not be located.
return 'The Directory was not found ('.$directory.'). Please check the directory path.';
}
}
}
?>
The example of it working online is here - as you can see 9 images all quickly flick up in the top left corner. They should load separately in the the top left of each rectangle…
here is a link to the fla (its too big for kirupa)
I’ve done what I thought was the hard bit, and i can’t think why the movie clips would reset back to 0,0 :h:. Well actually i done a test and they reset back to movie clip key1, where ever that is located.
Hope someone can explain why they don’t load into the predefine movie clip locations
Thanks in advance