Actionscript 3 如何在正在运行的应用程序中重新加载swf(重新加载类定义)?
我使用FlashPro和FlashBuilder。我在AIR中有一个应用程序,它从FlashPro中创建的SWF中读取资源 问题是,如果我在FlashPro中更改了某些内容并重新加载swf'a,则没有任何更改。我得到相同的符号,函数返回相同的数据 如果我再次运行应用程序并仅加载swf,那么我可以看到更改 看起来,如果AVM2(FlashPlayer)加载一个类,它确信这个类不会改变它的内容 我使用类加载器来加载swf 有人知道如何重新加载swf吗Actionscript 3 如何在正在运行的应用程序中重新加载swf(重新加载类定义)?,actionscript-3,apache-flex,flash,Actionscript 3,Apache Flex,Flash,我使用FlashPro和FlashBuilder。我在AIR中有一个应用程序,它从FlashPro中创建的SWF中读取资源 问题是,如果我在FlashPro中更改了某些内容并重新加载swf'a,则没有任何更改。我得到相同的符号,函数返回相同的数据 如果我再次运行应用程序并仅加载swf,那么我可以看到更改 看起来,如果AVM2(FlashPlayer)加载一个类,它确信这个类不会改变它的内容 我使用类加载器来加载swf 有人知道如何重新加载swf吗 我的职能: protected functio
我的职能:
protected function loadResourceFile() :void
{
if (_resourcesFile != null) {
_resourcesFile.unload();
_resourcesFile = null;
}
var ba :ByteArray = new ByteArray();
var fs :FileStream = new FileStream();
var srcFile : File = File.applicationDirectory.resolvePath(edResourcesSWF.text);
try {
fs.open(srcFile, FileMode.READ); // Otwarcie synchroniczne, można też asynchronicznie - openAsync()
fs.readBytes(ba);
fs.close();
} catch (e :Error) {
Alert.show('Błąd odczytu z pliku: ' + srcFile.nativePath + '\n\n' + e.message, 'Błąd');
return;
}
_resourcesFile = new Loader();
_resourcesFile.contentLoaderInfo.addEventListener(Event.COMPLETE, loadResourceFile_loaded);
_resourcesFile.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadResourceFile_ioErrorHandler);
try {
var context :LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
context.allowCodeImport = true;
context.allowLoadBytesCodeExecution = true;
_resourcesFile.loadBytes(ba, context); // <--- Load SWF
}
catch (e :Error) {
Alert.show('Nie można wczytać pliku zasobów: "' + edResourcesSWF.text + '"\n\n' + e.message, 'Błąd');
}
}
受保护的函数loadResourceFile():void
{
如果(_resourcesFile!=null){
_resourcesFile.unload();
_resourcesFile=null;
}
var ba:ByteArray=新的ByteArray();
var fs:FileStream=newfilestream();
var srcFile:File=File.applicationDirectory.resolvePath(edResourcesSWF.text);
试一试{
open(srcFile,FileMode.READ);//Otwarcie synchroniczne,można teżasynchronicznie-openAsync()
fs.readBytes(ba);
fs.close();
}捕获(e:错误){
Alert.show('Błd odczytu z pliku:'+srcFile.nativePath+'\n\n'+e.message,'Błd');
返回;
}
_resourcesFile=新加载程序();
_resourcesFile.contentLoaderInfo.addEventListener(Event.COMPLETE,loadResourceFile\u已加载);
_resourcesFile.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadResourceFile_ioErrorHandler);
试一试{
var context:LoaderContext=新的LoaderContext(false,ApplicationDomain.currentDomain);
context.allowCodeImport=true;
context.allowLoadBytesCodeExecution=true;
_loadBytes(ba,context);//这里有两件事……第一件事是,当您从不同的SWF加载同一个类时(本质上就是您正在做的事情),Flash假定它得到的第一个定义是正确的。您可以通过以下方式解决此问题,但我怀疑您的加载swf直接影响加载的类,因此这可能对您不起作用。我看到您选择在主上下文中加载所有内容,因此在更改之前,它肯定不会对您起作用那个
与其直接接触类,不如编程到接口(抽象类或基类也可以),并为主swf提供API,以从加载的swf请求接口的本地实现。这将允许您在应用程序上下文中隔离不同的类实现
第二个问题可能是swf正在被浏览器缓存。您可以通过在url:loader.load('http/:www.yourDomain.com/swfs/yourfile.swf?nocache='+getTimer()中添加一个参数来解决此问题我认为Flash Player/Adobe AIR可以假设编译后的资产在运行时不会更改。因此,可以假设如果重新编译资产,则必须重新加载/重新启动应用程序。您可以共享用于加载的代码吗?您是否尝试在重新加载之前为SWF指定不同的文件名?y如何你在运行时加载SWF?在重新加载之前如何“卸载”SWF?是的,我尝试更改SWF的名称,但没有帮助。可能是因为SWF中的类名是相同的。我在“Flash反编译程序Trillix”中检查了这一点。我在再次加载文件之前调用Loader.unload()
。查找。。。