如何实现php传递参数到flash

正在做的手机游戏增加了一个视觉效果,就是当玩家升级,或者是获得宝物的时候,会在通常结果页面显示之前,显示一段Flash动画。

虽然做法上有一些复杂,还好有好人已经做了Sample啦

携帯Flash (FLASH Lite 1.1) へ普通にパラメータを渡す

于是问题简单啦

CommonUtil.php

[sourcecode language=’php’]

function playFlashMovie($filename,$goto) {
header(“Content-Type: application/x-shockwave-flash”);

$base_url=$this->getUrlPath_();
$url=$base_url.$goto;
$file_url=WEB_SVR_RUL.”/flash/”.$filename;
echo $this->swf_wrapper($file_url,array(‘url’=>$url));

}

function swf_wrapper($file,$item) {
$tags = $this->build_tags($item);

$key = $file;
$cacheOptions = array (
‘cacheDir’ => ‘/home/xxx/cache/’,
‘lifeTime’ => ‘7200’,
‘automaticSerialization’ => ‘true’
);

$cache = new Cache_Lite($cacheOptions);
$data = $cache->get($key);

if($data){
$src = unserialize($data);
}else{
$src=file_get_contents($file);
$cache->save(serialize($src), $key);
}

$i = (ord($src[8])>>1)+5;
$length = ceil((((8-($i&7))&7)+$i)/8)+17;
$head = substr($src,0,$length);
return(
substr($head,0,4).
pack(“V”,strlen($src)+strlen($tags)).
substr($head,8).
$tags.
substr($src,$length)
);
}

function build_tags($item) {
$tags = array();
foreach($item as $k => $v) {
array_push( $tags, sprintf(
“\x96%s\x00%s\x00\x96%s\x00%s\x00\x1d”,
pack(“v”,strlen($k)+2), $k,
pack(“v”,strlen($v)+2), $v
));
}
$s = implode(”,$tags);
return(sprintf(
“\x3f\x03%s%s\x00”,
pack(“V”,strlen($s)+1),
$s
));
}

[/sourcecode]

battle_result.php

[sourcecode language=’php’]

$common = new CommonUtil();
$common->playFlashMovie(“16.swf”,”battle/battle_result.php?flashmode=xxxx”);

[/sourcecode]