你知道flex4 ModuleLoader和loadmodule的问题在哪里是bytearray吗?
ml.loadModule(“filewithswfcontent.php”,null); // -----完美的工作
ml.loadModule(null,bytearrayloadedbyurlloader); // ----没什么
这是我的mxml文件......
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="loadIndex();">
<fx:Script>
<![CDATA[
import mx.events.ModuleEvent;
private function loadIndex():void{
var urlreq:URLRequest = new URLRequest("index.php");
var urlloader:URLLoader = new URLLoader();
urlloader.addEventListener(Event.COMPLETE, loadIndexResult);
urlloader.load(urlreq);
}
private function loadIndexResult(event:Event):void{
var urlloader:URLLoader = event.target as URLLoader;
urlloader.removeEventListener(Event.COMPLETE, loadIndexResult);
var barray:ByteArray;
barray = (urlloader.data as ByteArray);
//ml.loadModule("index.php", null); // ----- WORKS PERFECTLY
ml.loadModule(null, barray); // ---- NOTHING
}
]]>
</fx:Script>
<s:ModuleLoader id="ml" width="500" height="500"/>
</s:Application>
答案 0 :(得分:1)
您必须进行两次修改
在loadModule中将一些字符串作为url。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="loadIndex();">
<fx:Script>
<![CDATA[
import mx.events.ModuleEvent;
private function loadIndex():void{
var urlreq:URLRequest = new URLRequest("index.php");
var urlloader:URLLoader = new URLLoader();
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
urlloader.addEventListener(Event.COMPLETE, loadIndexResult);
urlloader.load(urlreq);
}
private function loadIndexResult(event:Event):void{
var urlloader:URLLoader = event.target as URLLoader;
urlloader.removeEventListener(Event.COMPLETE, loadIndexResult);
var barray:ByteArray;
barray = (urlloader.data as ByteArray);
//ml.loadModule("index.php", null); // ----- WORKS PERFECTLY
ml.loadModule("MyModule", barray); // ---- WORKS PERFECTLY :)
}
]]>
</fx:Script>
<s:ModuleLoader id="ml" width="500" height="500"/>
</s:Application>