我正在使用PHP代码加载Flex 4.5模块(它是一个SWF文件),如下所示:
$module = 'modules/'.$_GET['module'].'.swf';
if(!file_exists($module)) {
$module = 'error.swf';
}
$size = filesize($module);
$contents = file_get_contents($module);
header('Content-Type: application/x-shockwave-flash');
header('Accept-Ranges: bytes');
header('Content-Length: '.$size);
echo $contents;
,它运行得非常好。
现在我想获得一些额外的数据来加载,并在一个请求处理程序中使用这些数据填充模块,例如:
private function requestHandler(response:???):void {
var data:Array = response as Array;
mySparkModuleLoader.load("", data[0] as ByteArray);
myController.load(data[1]);
}
我试图用AMFPHP做它,但ByteArray似乎被打破了,因为它没有出现,但其余的数据是好的:
return array(
'hello world!',
new Amfphp_Core_Amf_Types_ByteArray(file_get_contents($module))
);
也许创建一个多部分响应,如http://sun3.org/archives/107和处理它?
OMG正在工作!
我希望这将对其他人有用,所以:
AMFPHP 2.0 RC1服务:
<?php
class Services {
public function getModule() {
$path = dirname(__FILE__).''..'..'Modules'Foo.swf';
$ba = new Amfphp_Core_Amf_Types_ByteArray(file_get_contents($path));
return array(
$ba,
array(
'colors' => array(
'red',
'green',
'blue'
),
'animals' => array(
'dog',
'cat'
)
)
);
}
}
服务(使用Flex SDK 4.5)处理程序:
private function resultHandler(event:ResultEvent):void {
var response:Array = event.result as Array;
moduleLoader.loadModule("http://some.random.url", response[0] as ByteArray);
initialData = response[1] as Array;
}
就是这样!