-
Juvenile Delinquent
php/flash - POST doesn't work but GET does!
I have the following php code:
PHP Code:
<?php
// connect to the database
.....removed.....
$query = "SELECT id FROM takensquares WHERE id BETWEEN 1 AND 10000 AND taken = 1";
$result = mysql_query($query) or die(mysql_error());
// count rows of array
$num = mysql_numrows($result);
echo "mclocation=";
// output array results separated by commas
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
echo $id,",";
$i++;
// print "status=Connection successful...&checklog=5";
}
echo "null";
?>
This picks up the values in the db and sends to flash. The output looks like mclocation=5,8426,NULL
No probs but I want to change the query line to:
PHP Code:
$query = "SELECT id FROM takensquares WHERE id BETWEEN '$from' AND '$to' AND taken = 1";
Now I use POST to get "$from" and "$to" from the flash file. Only problem is that this doesn't seem to work. So I tried:
PHP Code:
$from = $_GET ['from'];
$to = $_GET ['to'];
and put the variables in to the url and it worked fine (I got mclocation=5,8426,NULL again). How come GET works and POST doesn't? I've checked the vars in flash by putting in 2 dynamic text boxes and I get 1 and 10000 respectively but they are either not going in to the php query or something else I don't know about is happening.
Just can't get my head around this Any ideas?
-
FK'n_dog
I use POST to get "$from" and "$to" from the flash file
can you show the actionscript for this ?
-
Juvenile Delinquent
I have on a keyframe the following:
Code:
fx = _xmouse / 80;
fx = Math.floor(fx) * 10000;
fy = _ymouse / 80;
fy = Math.floor(fy) * 100000;
tx = _xmouse / 80 + 0.00001;
tx = Math.ceil(tx) * 10000;
ty = _ymouse / 80;
ty = Math.floor(ty) * 100000;
if (_ymouse < 800) {
from = fx + fy + 1;
to = tx + ty;
}
This is where the from and to variables are created. Basically the movie is 800 x 880 px. Only 800 x 800 off the movie is clickable (the bottom 80px is a status bar the user cannot interact with - hence the if statement). So when the user clicks on the grid in the 800x800px square it captures the coordinates of the mouse and runs it through the equation above.
As I've said I put 2 dynamic text boxes with vars 'from' and 'to' in the properties and it shows them come up but it ain't getting passed to the php.
Here is the actionscript that loads the php file:
Code:
mc = new Array();
lv = new LoadVars();
lv.onLoad = function() {
resultsfromphp = this.mclocation;
mc = this.mclocation.split(",");
for (i=0; i<mc.length; i++){
var taken:MovieClip = _root.takensquare.duplicateMovieClip("takensquare"+i, _root.getNextHighestDepth());
// work out x position for movieclips
xwork = mc[i] - 1;
xloc = xwork;
xwork = xwork / 100;
xwork = Math.floor(xwork);
xwork = xwork * 100;
xloc = xloc - xwork;
xloc = xloc * 8;
// work out y position for movieclips
yloc = mc[i] - from + 1;
yloc = yloc / 100;
yloc = Math.floor(yloc);
yloc = yloc * 8;
taken._y = yloc;
taken._x = xloc;
}
};
lv.load("takensquares.php");
Basically it checks a db and puts a movieclip on the stage for each record depending on the records id. It's just not getting the info.
Thanks again (I would be lost without FK!)
Last edited by CVO Chris; 02-01-2008 at 08:54 PM.
-
FK'n_dog
try using the LoadVars.sendAndLoad method -
PHP Code:
lv = new LoadVars();
trace(to); trace(from);
lv.to = to;
lv.from = from;
lv.sendAndLoad("takensquares.php", lv, "POST");
lv.onLoad = function() {
// use returned vars
}
-
Juvenile Delinquent
Works perfectly! Thanks for your help buddy
-
sendAndLoad works for Actionscript 2, any idea how to make it work for AS3?
-
FK'n_dog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|