How to load a SWF and some extra data in the same request?
-
07-02-2021 - |
سؤال
I'm loading a Flex 4.5 module (it's a SWF file) using a PHP code like this:
$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;
and it works very well.
Now I want to get some extra data to load and populate the module with that data in just one request handler, something like:
private function requestHandler(response:???):void {
var data:Array = response as Array;
mySparkModuleLoader.load("", data[0] as ByteArray);
myController.load(data[1]);
}
I was trying to do it with AMFPHP but the ByteArray seems to be broken or something because it doesn't show up, but the rest of the data is fine:
return array(
'hello world!',
new Amfphp_Core_Amf_Types_ByteArray(file_get_contents($module))
);
Maybe creating a multipart response like http://sun3.org/archives/107 and handling it?
Any idea will be welcome.
المحلول
OMG IS WORKING!
I hope that this will be useful to someone else so:
The AMFPHP 2.0 RC1 service:
<?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'
)
)
);
}
}
The service (using Flex SDK 4.5) handler:
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;
}
And that's it!
لا تنتمي إلى StackOverflow