FLASH AS2和PHP变量

时间:2012-10-13 07:47:59

标签: php flash

我的Flash电影将数据读取并发送到免费服务器中的PHP文件。如果以这种方式写入文件文件(由PHP文件管理),Flash似乎可以从中读取变量值:& variable = value&,我没有问题。 但我的PHP文件,由Flash发送的预处理(通过某些数学函数)数据,然后更新文本文件中的值,这是我的意图,但我无法完成它。 假设我想更新一个计数器(它计算数据更新的次数): 在文本文件中我有&counter=0&(初始值),如果我输入PHP文件:

<?php
$fp = fopen("jose_stats.txt", "r");// I guess with it, I've read all the variables and values
// one of them is the variable &counter.
fclose($fp);

$toSave = "&counter=&counter+1&\n";

$fp = fopen("jose_stats.txt", "w");
if(fwrite($fp, "$toSave")) { 
  echo "&verify=success&"; //prints to screen &verify=success which flash will read
                          //and store as myVars.verify
   } else { // simple if statement
      echo "&verify=fail&"; //prints to screen &verify=fail which flash will read and
                           //store as myVars.verify
     }
   fclose($fp);

?>

但是,我检查了我的文本文件,它有&counter=&counter+1&行:(而不是预期的&counter =1&。 请给我并提出建议。谢谢。

1 个答案:

答案 0 :(得分:1)

为什么不使用JSON?

只需以JSON格式存储数据:

$count = 1;

$toWrite = array( 'count' => $count );//put other data into this array if you want

//encode it
$toWrite = json_encode( $toWrite );

//and now write the data

要在flash中解码,请导入JSON类:

使用JSON.as类的as2中的JSON示例:

try {
  var o:Object = JSON.parse(jsonStr);
  var s:String = JSON.stringify(obj);
} catch(ex) {
  trace(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
}

所以只需导入class,然后运行JSON.parse( yourPhpResponse );

此外,您在文本文件中看到&counter=&的原因是因为您将其存储为:$toSave = "&counter=&counter+1&\n";

相关问题