tags:

views:

469

answers:

6

here is the code

<php?  
$id1 =1;
$id2 = "module 1 loaded";
echo "$var1=$id1","$var2=$id2";
?>

i know this is not correct way how can i pass these two varables to flash

+2  A: 

If you want to create a script which outputs data which can be loaded with LoadVariables or LoadVars you need something like this

//set up your values 
$vars=array();
$vars['foo']='bar';
$vars['xyz']='123';

//output     
header ("Content-Type: application/x-www-urlformencoded");
$sep="";
foreach($vars as $name=>$val)
{
    echo $sep.$name."=".urlencode($val);
    $sep="&";
}

If your version of PHP supports it, http_build_query makes this even easier:

$vars=array();
$vars['foo']='bar';
$vars['xyz']='123';

header ("Content-Type: application/x-www-urlformencoded");
echo http_build_query($vars);
Paul Dixon
+1  A: 

Shouldn't it just be in the form of a query string:

echo $var1.'='.$id1.'&'.$var2.'='.$id2;

Make sure the keys and values are urlencoded.

I still think http_build_query() is much easier than doing it this way.
Peter Bailey
+2  A: 

Paul Dixon's code snip is what you need on the PHP side. Here's the flash part:

myVars = new LoadVars(); 
myVars.load("http://localhost/foo.php");

myVars.onLoad = function (success) {
     if (success) {
        for( var attr in this ) {
            trace (" key " + attr + " = " + this[attr]); 
        }
    } else {
        trace ("LoadVars Error"); 
    }
}

Note, you will want to replace the loop logic with whatever your application requires.

fuentesjr
+6  A: 
<?php

echo http_build_query( array(
     'var1' => 1
    ,'var2' => 'module 1 loaded'
));
Peter Bailey
A: 

PHP Code:

<php?  
$id1 =1;
$id2 = "module 1 loaded";

print "&var1=$id1";
print "&var2=$id2";

?>

I am sure this will work...

A: 

Flash Code:

btn.onPress = function(){

   testLoadVars = new LoadVars();

   testLoadVars.onLoad = function(success){

      if(success){
         trace(testLoadVars.var1);
         trace(testLoadVars.var2);
      }
      else
         trace("error");
   }
   testLoadVars.sendAndLoad("http://localhost/filename.php?uniqueID=" +  getTimer(),testLoadVars,"POST");

}

That's all.. Any Problem faced??