所以,由于之前帖子的剪切量,我一直在避免发布这个问题。我已经尝试了以下代码的几种变体,但无济于事。
我使用FireFox(最新),Flash Player(最新),AS3和几行JavaScript。
这是我的AS3:
import flash.external.*;
// Handling Count For External Refreshing
var count: Number = 0;
var countMax: Number = 3;
function countHandler(): void {
if (count >= countMax) {
trace("The count has reached the max " + countMax);
ExternalInterface.call("refresh");
count = 0;
} else {
trace("The Count is " + count)
return;
}
}
我已经跟踪了计数,总计,所有这些,所以我知道代码正在运行。它甚至会在count
3
这是javascript:
<script language="JavaScript">
function refresh() {
window.location.reload();
}
</script>
对于咯咯笑/测试,我在页面上添加了一个按钮来测试上面的代码是否正常工作......
<input type="button" value="Reload Page" onClick="refresh()">
当我按下按钮时,它会刷新页面。
我有什么遗失的东西吗?为什么工作AS3不会通过触发工作的javascript来刷新页面?
当我单击按钮时,它会刷新,当代码通过ActionScript触发时,我无法按任何SWF按钮。所以它会被解雇,但实际上并没有刷新整个页面。
7月4日更新 - 更新了AS3和Java - 仍然没有运气
答案 0 :(得分:1)
感谢Akmozo的帮助。
将allowScriptAccess
设置为always
- 不是*
就像adobe教程所说的那样(混蛋)。 SWF不能有任何连字符或短划线。我必须将文件名设置为My.Test.File.fla
,因此当我导出/构建它时,输出以下flashContent
<div id="flashContent">
<object type="application/x-shockwave-flash" data="My.Test.File.swf" width="1920" height="1080" id="My.Test.File" style="float: none; vertical-align:middle">
<param name="movie" value="My.Test.File.swf" />
...
<param name="allowScriptAccess" value="always" />
...
</object>
</div>
有关命名法中符号的更多信息 - Here
这是我使用的ActionScript。
// Handling Count For External Refreshing
var count: Number = 0; //start count at 0
var countMax: Number = 3; //max whatever you need it to be
var isAvailable: Boolean = ExternalInterface.available; // checking if avail
trace(isAvailable);
function countHandler(): void {
if (count >= countMax) {
trace("The count has reached the max " + countMax); // Trace in flash
ExternalInterface.call("console.log", "testing..."); // Output to Console
ExternalInterface.call("refresh"); //fire the refresh script
count = 0; // reset the count
} else {
trace("The Count is " + count)
return;
}
}
这是java脚本。放在<head>
以下<style>
<script language="JavaScript">
function refresh() {
console.log("Try To Refresh");
window.location.reload();
}
</script>
我必须创建一个crossdomain.xml
文件才能允许访问。我已经使用crossdomain.xml
和不使用security sandbox
多次测试了该项目,如果没有它,我会收到allowScriptAccess="always"
错误。不确定为什么allowScriptAccess
无效。
<强>结论强>
因此,将*
设置为"refresh();"
似乎是一个坏主意。我从Adobe的一个安全沙箱教程中得到了这个(感谢Adobe)。此外,将ExternalInterface.call
传递给refresh
会查找没有的SWf
个参数。 -
文件名但不使用短划线MyFileName.swf
这样..
这...... My-File-Name.swf
不是这个...... setBounds()
此代码按预期执行。感谢大家的投入和帮助。