2015-02-24 66 views
0

我正在将Flash对象(swf文件)嵌入到HTML页面中。该对象使用as3编写,并使用Flash Builder构建。其目的是显示一些动画,然后完成。如何使用swfobject通知已完成SWF的HTML容器

这是真的对我很重要的是能够以通知动画结束容器,但我无法找到任何工作。我正在使用swfobject version 2.2

在Chrome 40和IE 11

HTML(样品)都尝试:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> 
    <script type="text/javascript" src="js/swfobject.js"></script> 
    <script type="text/javascript"> 
     function flashFinished() {alert('finished!');} 
    </script> 
    <script type="text/javascript"> 
     var flashVars = {} 
     var flashParams = {allowscriptaccess : 'sameDomain'} 
     var flashAttributes = {id : 'myflash', name : 'myflash'} 
     swfobject.embedSWF('myflash.swf', 'flashObject', '960', '720', '9.0.0', 'swf/expressInstall.swf', 
       flashVars, flashParams, flashAttributes); 
    </script> 
</head> 
<body> 
    <div id="flashObject"> 
     <p>To view this page please make sure that an updated version of Adobe Flash Player is installed.</p> 
    </div> 
</body> 

AS3(样品):

package 
{ 
    public class myflash extends Sprite 
    { 
     public function myflash() 
     { 
      stage.scaleMode = StageScaleMode.NO_SCALE; 
      stage.align = StageAlign.TOP_LEFT; 
      startPlay(); 
     } 
     private function startPlay() : void { 
      // do whatever, then make sure function finishPlay is called in the end 
     } 
     private function finishPlay(event:TimerEvent) : void { 
      if (ExternalInterface.available) 
       ExternalInterface.call('flashFinished'); 
     } 
    } 
} 

我 “flashFinished” 功能被从来没有所谓。任何人都可以建议我做错了什么?谢谢!

+0

我会去与ExternalInterface调用,你有没有试过一个警报,看看它是否工作? - > ExternalInterface。呼叫(“警报”,“来自Flash的呼叫”); – Shaeldon 2015-02-24 10:59:19

+0

我认为你的代码很好,但是如果你在本地尝试它,你可能会得到一个安全异常,所以在Web服务器上试试它。 – akmozo 2015-02-24 11:19:59

+0

@Shaeldon SecurityError:错误#2060:安全沙箱冲突:ExternalInterface调用者文件:/// C:/...../myflash.swf无法访问file:/// C:/...../page。 HTML。毕竟,akmozo看起来是对的。 – 2015-02-24 18:12:13

回答

1

为了避免这种情况的Flash播放器块本地的SWF访问到外部URL(互联网,...),或使用JavaScript或者某些通信的其他行为火一般的安全沙箱冲突错误,你必须添加它(该SWF)受信任位置的这样的名单:

对于Flash Player PPAPI(如Opera和Chrome):

  • 右键单击您的SWF在浏览器中,然后全局设置打开。 ..

enter image description here

将打开this page

enter image description here

  • 然后,它在图像真实提到,点击编辑位置...组合框和添加位置,它会给你这个框:

enter image description here

你刚才输入您的SWF文件的位置,或者它的父目录,或者干脆整个分区像什么,我的形象一样。尽量避免“浏览...”按钮,有时它不起作用(至少对我而言)。 确认并关闭页面并刷新您的swf。

对于Flash Player的ActiveX(如IE)和NPAPI(如Firefox):

  • 对您的SWF在浏览器中打开右键单击,然后全局设置...,你也可以去您的系统控制面板,打开Flash播放器

enter image description here

  • 然后去高级选项卡并单击受信任位置设置...按钮:

enter image description here

  • 然后,你必须添加使用瑞士法郎位置Add .. button >添加文件...添加文件夹...按钮>选择您的文件/目录或分区,然后按OK确认并关闭所有对话框。

enter image description here

然后你刚刚刷新页面。

1

如果闪存代码工作已经完成,你不需要它了,刚刚结束的JavaScript在AS3:

var exitStr:String = "javascript:terminate()"; 
navigateToURL(new URLRequest(exitStr),"_self"); 

,然后添加HTML中的onunload的功能,这将在那个被称为点:

onUnload="flashFinished();" 

注:我用这个代码与swfobject的V1.4不能确定V2.2

+0

SecurityError:错误#2051:安全沙箱违例:file:/// C:/...../myflash.swf无法评估file:///中的脚本URL C:/...../ mypage.html(allowScriptAccess是同一个域)。尝试的URL是javascript:terminate()。 – 2015-02-24 18:07:45

0

它实际上是安全问题,由于当地的环境,通过@akmozo的建议。我去到Flash Player的全局安全设置:

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

,并添加了树contaning所有HTML页/ SWF对象允许位置的根文件夹。所以现在它也适用于本地。

+0

我认为把答案解释一切;)是的,这是用于Flash Player PPAPI(如Opera和Chrome),用于Flash Player ActiveX(如IE)和NPAPI(如Firefox),它在控制面板中> Flash Player >高级选项卡>受信任的位置设置...或简单地右键单击>全局设置... – akmozo 2015-02-24 19:14:05

+0

为避免出现此类问题,您可以只添加整个分区,例如'c:\'... – akmozo 2015-02-24 19:16:38

+0

@akmozo是的,如果您我会选择并投票 – 2015-02-25 10:50:15