PDA

View Full Version : getting in array info from php


issamneo
05-21-2004, 05:21 AM
hi everybody
i want to put in an flash array the names of files found in a directory
this the php script:


<?
$i = 0;
$dir = ".";
$handle=opendir($dir);
while ($file = readdir($handle)) {
if($file=='.'||$file=='..')
continue;
$filetlist [$i] = $file;
$i++;
}
$numRows = count($filetlist);
print "&total=$numRows";
for ($i=0; $i<$numRows; $i++){
echo "&file$i=".$filetlist [$i];

}
?>

and there is th AS 2 script:

GetPaths = new LoadVars();
flasharray = new Array;
GetPaths.onLoad = function(success) {
var x:Number ;
x = this.total;
for (i=0;i<x;i++){
flasharray[i]=GetPaths["file"+i];
trace ("number"+i+" " +flasharray[i]);
}
};
GetPaths.sendAndLoad("http://127.0.0.1/test/test3.php", GetPaths, "POST");
// GetPaths["file"+i]
for(j=0;j<flasharray.length;j++){
trace (flasharray[j]);
}

why when i trace the flasharray[i] in the loop for (i=0;i<x;i++) it sends the name of files it's OK but
after when i trace them: for(j=0;j<flasharray.length;j++) it don't work WHY!!!

CyanBlue
05-21-2004, 08:00 AM
Howdy... :)

That's got to do with the order Flash plays the commands...
Your for loop with J probably gets fired before the for loop...
Move your J for loop to the next frame and it should work...

issamneo
05-21-2004, 08:55 AM
i try it(next frame) but without any result

CyanBlue
05-21-2004, 12:15 PM
First of all, I don't use FMX 2004, so you've got to make any necessary change with AS 2.0... :)
Try this on frame 1...

stop();
GetPaths = new LoadVars();
_global.flasharray = new Array();
GetPaths.onLoad = function(success) {
var x:Number ;
x = this.total;
for (i=0;i<x;i++){
flasharray[i]=GetPaths["file"+i];
trace ("number"+i+" " +flasharray[i]);
}
_level0.gotoAndStop(2);
};
GetPaths.sendAndLoad("http://127.0.0.1/test/test3.php", GetPaths, "POST");

This goes to frame 2...

stop();
// GetPaths["file"+i]
for(j=0;j<_global.flasharray.length;j++){
trace (_global.flasharray[j]);
} and tell me what Flash says... :)

dr.swank
05-21-2004, 06:40 PM
<?
$i = 0;
$dir = ".";
$handle=opendir($dir);
while ($file = readdir($handle)){
if($file=='.'||$file=='..')
continue;
$filetlist [$i] = $file;
$i++;
}
$numRows = count($filetlist);
var $out= "&out=";
for ($i=0; $i<$numRows; $i++){
$out += "||".$filetlist [$i];

}
echo $out
?>


this should give you a splitable string in your loadVars object which you can split back into an array as such:


stop();
GetPaths = new LoadVars();
_global.flasharray = new Array();
GetPaths.onLoad = function(success) {
my_array=this.out.split("||");
trace(my_array);
};
GetPaths.sendAndLoad("http://127.0.0.1/test/test3.php", GetPaths, "POST");


see if this works for you.
cheers, doc

issamneo
05-24-2004, 03:25 AM
thank you both
cyan blue i got it to work now without any change
Dr swank really good idea but i got an error in line 12 : var $out= "&out=";

dr.swank
05-24-2004, 07:43 AM
hmm, it could have to do with the 'var' before the $out... php is not my strength. glad you got it worked out.

doc

CyanBlue
05-24-2004, 08:06 AM
Yeah... What Doc said...

This one gives you an error...

<?php
var $out = "&out=";
echo($out);
?>
But you don't get any error as soon as you take the 'var' out of that line...