今天在FB4上将最近做的一个demo导出为swf文件运行,很奇怪的是在FB中随便怎么改运行都没有问题,一开始怀疑是路径问题,后来也改成了绝对路径方式,但是导出后仍然不能正常运行。
当然这一系列过程中也不是一无所获:
1、FB中编译的一般都在bin-debug中调试运行,如何导出为web应用能使用的呢,可以参考FB的帮助说明。
- 首先,在项目”属性—构建路径“中 选择“合并到代码中“,这样你所引用的swc文件就可以包含到你的代码中了。
- 选择项目,右键,在”导出“中选择”发行版本“,然后选择你要导出的应用模块,导出后,工程下会生成一个bin-release的文件夹
- 拷贝这个文件到你的web目录下,运行
2、如何获取当前swf文件运行的绝对路径?
private function getAbsPath():void { var swfPath:String = this.parent.stage.loaderInfo.url;//获取当前swf的路径 var swfPathArray:Array = swfPath.split("/"); if (swfPathArray[0] == "file:") { //本地路径 if(swfPathArray.length<=3){ currSwfUrl = swfPathArray[2]; currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf(currSwfUrl.charAt(2))); } else{ currSwfUrl = swfPath; currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/")); } }else{ //网络路径 currSwfUrl = swfPath; currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/")); } currSwfUrl += "/"; }
回归正题,在不断google、不断测试,不断失望后,突然找到国外的一篇帖子,以下是原文:
写道
Error #2148 is a very strange error that I get when I load xml files from the local machine. It’s strange because I only get it with Flex 3 and I don’t get the error all the time when I load xml files.
[RPC Fault faultString=”Error #2148: SWF file file:///D:/_path_to_file_/Main.swf cannot access local resource assets/xml/config.xml. Only local-with-filesystem and trusted local SWF files may access local resources.” faultCode=”InvokeFailed” faultDetail=”null”
So the quick fix is to add this arguments to the compiler:
-use-network=false
Go to Project -> Properties -> Flex Compiler and add -use-network=false to Additional compiler arguments
If you got the #2148 Error in a different situation let me know and I will post you comments/solutions.
[RPC Fault faultString=”Error #2148: SWF file file:///D:/_path_to_file_/Main.swf cannot access local resource assets/xml/config.xml. Only local-with-filesystem and trusted local SWF files may access local resources.” faultCode=”InvokeFailed” faultDetail=”null”
So the quick fix is to add this arguments to the compiler:
-use-network=false
Go to Project -> Properties -> Flex Compiler and add -use-network=false to Additional compiler arguments
If you got the #2148 Error in a different situation let me know and I will post you comments/solutions.
意思很明显了,就是你编译的应用,如果是使用了本地运行方式,不需要使用外部的访问,那在编译的时候需要加上编译参数:
-use-network=false
具体操作就是" Project -> Properties -> Flex Compiler and add -use-network=false to Additional compiler arguments"
加入后,编译,再导出,测试,ok,问题解决!