首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex生成的swf为何只能在工程bin-debug目录下才能运行正常,高人帮看看

2013-03-26 
flex生成的swf为什么只能在工程bin-debug目录下才能运行正常,高人帮看看flex生成的swf为什么只能在工程bin

flex生成的swf为什么只能在工程bin-debug目录下才能运行正常,高人帮看看
flex生成的swf为什么只能在工程bin-debug目录下才能运行正常,高人帮看看
[解决办法]
首先,你如果是放本机上在非bin-debug目录下,并调用ExternalInterface的任何属性,都会引发安全沙箱错误;假如你放在服务器上,应该没有错吧,下面是我测试的两个文件,点击button后可以正常返回值:
// html文件

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello</title>
<style>
body { margin: 0px; overflow:hidden }
</style>
<script type="text/javascript">
  function executeAsFunction(){
  var result = document.getElementById("TestNew").asFunction("1", "2");
  alert(result);
  }
</script>
</head>

<body scroll="no">
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="TestNew" width="100" height="100"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="TestNew.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="TestNew.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="TestNew" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
<hr/>
<button id="btnTest" onclick="executeAsFunction()">TEST</button>
</body>
</html>


// mxml文件
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="12" creationComplete="initApp()">  
    <mx:Script>
    <![CDATA[
    public function initApp():void {
    if(ExternalInterface.available) {
    ExternalInterface.addCallback("asFunction", 
    function(param1:String, param2:String):String {
    return "Hello " + param1 + param2;
    }
    );
    }
    }
    ]]>
    </mx:Script>
</mx:Application>  

热点排行