Page 1 of 2

How to pass parameters from php to flash?

Posted: Tue Oct 25, 2011 9:56 am
by Huynh
sorry, if I am wrong forum.I know in php to pass parameters, use:
<name>. php? variable = <value>
And $ _REQUEST to get.
I was able to transfer from flash to php.I'm having trouble both transmission and reception.How to transfer values ​​from php to flash?Flash supports the same function with the function '$ _REQUEST'?
thank

Re: How to pass parameters from php to flash?

Posted: Tue Oct 25, 2011 11:02 am
by egg82
flash to php:
yoursite.com/page.php?var1=value1&var2=value2

php to flash:
echo("var1=".$value1."&var2=".$value2);

make sure you're saving the variables to an MC in your frame so you can use them
The variable names in your MC are the same as the ones echoed in PHP

Re: How to pass parameters from php to flash?

Posted: Tue Oct 25, 2011 11:49 am
by flying_circus
Huynh wrote:sorry, if I am wrong forum.I know in php to pass parameters, use:
<name>. php? variable = <value>
And $ _REQUEST to get.
I was able to transfer from flash to php.I'm having trouble both transmission and reception.How to transfer values ​​from php to flash?Flash supports the same function with the function '$ _REQUEST'?
thank
Look into using fscommand (google: "flash fscommand"). This will allow your flash object to interact with a jscript on your page. Once you connect those dots, you can use PHP to output data within a dynamically generated jscript, or you can use jscript to make AJAX calls and fetch data from PHP asynchronously.

Re: How to pass parameters from php to flash?

Posted: Tue Oct 25, 2011 11:58 am
by egg82
I can show you what exactly I used for mine, but flash takes forever to open on my computer, so i'll post a link instead.

http://www.kirupa.com/developer/actions ... _mysql.htm

Re: How to pass parameters from php to flash?

Posted: Thu Oct 27, 2011 10:23 am
by Huynh
thank the good idea.
I found:

Code: Select all

$nome="";
$x="10";
$alpha="2";
$vars .= "" ;
......
$row=mysql_fetch_row($result);
$vars .= "nome=" . $nome . "&" ;
$vars .= "x=" . $row[1] . "&" ;
$vars .="alpha=".$alpha."&";
echo $vars
in flash:

Code: Select all

myVars = new LoadVars ();
// call the load method to load my php page
myVars.load( "http://localhost/read1.php" );
//trace(myVars.nome)
//trace(myVars.x)
//trace(myVars.alpha) // "pietro@flash-php.it" 
myVars._path = this 
myVars.onLoad = function(success){
if (success){
//trace (" variables loaded ");
tposx.text=myVars.x;
tposy.text=myVars.y; // "pietro"
mc_rect._alpha=int(myVars.alpha);
} else {
trace (" Error loading variables ");
}
Everything is fine except mc_rect not disappear with alpha = 2.

Re: How to pass parameters from php to flash?

Posted: Thu Oct 27, 2011 4:54 pm
by egg82
try loadVariables instead.

And use _root.mc_rect

Re: How to pass parameters from php to flash?

Posted: Fri Oct 28, 2011 4:03 am
by Huynh
Your idea is great.I appreciate it.
I have a movieclip named mc_soldiers and I have tried:

Code: Select all

mc_soldiers.loadVariables ('localhost/read1.php','');
_root.mc_soldiers._x = parseInt (myVars.x);
_root.mc_soldiers._alpha = parseInt (myVars.alpha);
With alpha and x in php is 2 and 10 (second and third columns of the database).Put all the code on the event onRelease of a button.It worked.Mc_soldiers become transparent.Movieclip has moved.
I added two columns in mysql.
Our name is 'account, pass'.
Each account will have x, y and alpha in its own
add into read1.php:

Code: Select all

$name=$_POST["uname"];
$pass=$_POST["passw"]; 
....
$query = mysql_query ( "SELECT * FROM $table WHERE account = '".$name."' and pass='".$pass."'");
$num = mysql_num_rows ( $query );
if( $num > 0 )
{
     $row=mysql_fetch_row($query);
     $vars="";
     $vars.="alpha=".$row[5]."&";//I checked column
    ....
     echo $vars;
[b][color=#804080]}
my actionscript:[/color][/b]

Code: Select all

submit.onRelease = function(){
//call php to verify the correct username and password 
var myVars: LoadVars = new LoadVars();
    myVars.uname = tuser.text;
    myVars.passw = tpass.text;
    myVars. onLoad = function(success){ 
	if ( success ) {
            msgbox.text = "ok" ;
	} else {
            msgbox.text = "not ok" ;
	}
};
             myVars.sendAndLoad ( "read1.php" , myVars, 'POST' ) ;
};
success.But the variable x, alpha received was undefined. :|
what happened?
I want to get the alpha value after logging

Re: How to pass parameters from php to flash?

Posted: Fri Oct 28, 2011 11:28 am
by egg82
mc_soldiers.loadVariables ('localhost/read1.php','');
should be
_root.mc_soldiers.loadVariables ('localhost/read1.php', 'GET');

never assume in flash :P

Code: Select all

$result = mysql_query ( "SELECT * FROM `".$table."` WHERE `account` = '".$name."' AND `pass`='".$pass."'");
if(!$result){
     echo(mysql_error());
     exit();
}
if(mysql_num_rows($result) == 0){
     echo("no results returned");
     exit();
}
$row = mysql_fetch_array($result);
echo("alpha=".$row["alpha"]);
if it's returning undefined, open the php page with your browser and check for errors in the PHP code. I guarantee that's what it is.

Oh, and GET is slightly faster than POST, but POST can send more data (my understanding)

Re: How to pass parameters from php to flash?

Posted: Sat Oct 29, 2011 4:42 am
by Huynh
I get this error when running the php:
Notice: Undefined index: uname in C:\xampp\htdocs\read1.php on line 14
Notice: Undefined index: passw in C:\xampp\htdocs\read1.php on line 15
no results returned.
read1.php:

Code: Select all

14.$name=$_POST["uname"];
15.$pass=$_POST["passw"];
I think uname and passw is in the flash :?

Re: How to pass parameters from php to flash?

Posted: Sat Oct 29, 2011 5:25 pm
by egg82

Code: Select all

if(isset($_POST["uname"])){
$name = $_POST["uname"];
}
if(isset($_POST["passw"])){
$pass = $_POST["passw"];
}
echo("Username: ".$name);
echo("Password: ".$pass);
the echos are just there for debugging. Use them to find out exactly what strings are being passed through your $_POST

Re: How to pass parameters from php to flash?

Posted: Sat Oct 29, 2011 11:57 pm
by Huynh
I tried your code.It informs $name and $pass is empty.
when I

Code: Select all

trace (myVars)
, I get the onLoad=%5Btype%20Function%5D&passw=123&uname=John.
sendAndLoad replaced by

Code: Select all

'myVars.send ("http://localhost/read11.php", "_blank", "POST");'
Your code worked.But it opens up a php page in the browser.php I want to hide when it action.
But after four hours long, I've found a solution.Instead of using '$ _POST' I use $ _REQUEST.The database connection as usual.
php:

Code: Select all

if ($ num> 0)
{
$ row = mysql_fetch_row ($ query);
echo ("&result_ =". $row [2 ]);// 2 is the column containing alpha
$ alpha = $row [2];
$ vars = "";
$ vars .= "Nome = &";
$ vars .= "alpha =". $ alpha ."&";
echo $ vars;
}
I added a global variable php_process: new LoadVar
actionscript:

Code: Select all

submit.onRelease = function () {
var myVars: LoadVars = new LoadVars ();
     myVars.uname = tuser.text;
     myVars.passw = tpass.text;
myVars.sendAndLoad ("http://localhost/read11.php" php_process, "POST");
};
     php_process.onLoad = function (success) {
if (success) {
             msgbox.text = php_process.result_;
Else {}
             msgbox.text = "not send";
}
};
php_process will contain all the information from php
the movieclip:

Code: Select all

_root.troop._alpha = php_process.alpha;
Ctrl + Enter.
I get nothing.Open server directory path.Run Login.swf in it-> message: localhost local internet connection.I run localhost / xampp with IE.
Ctrl + Enter again.Its work.Transmit and receive effective.
Only one thing is to run 'login.swf' localhost folder, it appears to try to connect 'allow-internet' localhost.
So, I have trouble when I send 'login.php' and 'Login.swf' to the server.If a freehost, I note what?

Re: How to pass parameters from php to flash?

Posted: Sun Oct 30, 2011 12:58 am
by egg82
again, I would suggest LoadVariables
'myVars.send ("http://localhost/read11.php", "_blank", "POST"); is opening your PHP script in a blank(_blank) window.

LoadVariables uses URL injection, so your $_POSTs won't work

Re: How to pass parameters from php to flash?

Posted: Mon Oct 31, 2011 6:29 am
by Huynh
I'm nearly.Login only to flash a record.Simple.If I replace

Code: Select all

$ row = myssql_fetch_row ($ res) 
with

Code: Select all

while ($ row = myssql_fetch_array ($ res)){
   //What is there to send to flash?  
}
:roll:
For example enter search terms in flash, php will find and send to flash.It will be sent to the flash array.How do I send an array in php to flash?What to do to receive and display the array from php in 'flash'?

Re: How to pass parameters from php to flash?

Posted: Mon Oct 31, 2011 9:11 am
by egg82

Code: Select all

echo("returned=true");
$i=0;
while ($ row = myssql_fetch_array ($ res)){
    $i++;
    echo("&variable".$i."=".$row["column"]);
}
echo("&last=".$i);
flash:
for(i=0;i<=this.last;i++){
_root.msgbox.text += "\n"+this["variable"+i];
}

Re: How to pass parameters from php to flash?

Posted: Fri Nov 04, 2011 12:51 am
by Huynh
Also use '& variable =' to send an array to flash.Sent from php is nice.But there is something in this ["variable" + i]It is undefined.When I replacethis ["variable" + i] by receive.variable1, it ok.An array is arrayVar [num] in flash.
I do not understand: what is this ["variable" + i]?
I'm thinking 'receive.variable + i'-> receive.variable1, receive.variable <n>
H ow? :?