繁体   English   中英

FLASH AS2和PHP变量

[英]FLASH AS2 and PHP variables

我的Flash电影读取免费服务器中的数据并将其发送到PHP文件。 如果Flash以这种方式编写变量值,则可以从文本文件(由PHP文件管理)中读取变量值:&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& 。请给我建议,谢谢。

为什么不使用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);
}

因此,只需导入该类 ,然后运行JSON.parse( yourPhpResponse );

另外,在文本文件中看到&counter=&的原因是因为要像这样存储它: $toSave = "&counter=&counter+1&\\n";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM