1

我正在使用这样的 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这样的多部分响应并处理它?

任何想法都会受到欢迎。

4

1 回答 1

1

天哪!

我希望这对其他人有用,所以:

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;

}

就是这样!

于 2011-10-07T10:25:33.650 回答