How to pass parameters from php to flash?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

How to pass parameters from php to flash?

Post 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
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: How to pass parameters from php to flash?

Post 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.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post by egg82 »

try loadVariables instead.

And use _root.mc_rect
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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)
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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 :?
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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?
Last edited by Huynh on Sun Oct 30, 2011 4:34 am, edited 1 time in total.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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'?
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: How to pass parameters from php to flash?

Post 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];
}
Huynh
Forum Newbie
Posts: 10
Joined: Sat Oct 08, 2011 1:51 am

Re: How to pass parameters from php to flash?

Post 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? :?
Post Reply