IE浏览器中的flash as3播放器

时间:2011-12-15 18:12:37

标签: actionscript-3 internet-explorer flash

我正在尝试创建一个简单的音频Flash播放器,在点击时调用js函数,它在除IE之外的所有浏览器中都能很好地工作。我无法弄清楚似乎是什么问题!

这里是html:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <meta http-equiv="Content-Type" content="text/html;  charset=ISO-8859-1" />
    <title>player</title>
    </head>
    <body >

    <![if !IE]>
    <object type="application/x-shockwave-flash" classid="bla" width="18" height="30"               id="myFlashMovie"> 
<param name="wmode" value="opaque" />   
<param name="FlashVars" value="mp3.mp3" />
<embed type="application/x-shockwave-flash" width="18" height="30"      src="player%2Eswf" id="flashObj" FlashVars="audioTrackPath=mp3%2Emp3" />
    </object>
    <![endif]>

    <!--[if IE]>
    <object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-  96b8-444553540000" width="18" height="30" id="movie" allowScriptAccess="sameDomain" >
    <PARAM NAME="movie" id="movie" value="player%2Eswf?audioTrackPath=mp3%2Emp3"/>
<PARAM NAME="FlashVars" value="mp3%2Emp3" />
<PARAM NAME="allowScriptAccess" value="always" />   
    <![endif]-->    


    <script type="text/javascript">
    alert("Hello World");
    </script>
    <noscript>Sorry, your browser does not support JavaScript!</noscript>

    <script type="text/javascript">
    function countdown() {
            alert("countdown");
                }
    </script>   
    </body>
    </html>

以下是:

    import flash.media.Sound;
    import flash.media.SoundLoaderContext;
    import flash.net.URLRequest;
    flash.system.Security.allowDomain("http://localhost");



    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    var audioTrackPath:String = String(paramObj['audioTrackPath']);


    stop();
    play_btn.addEventListener(MouseEvent.CLICK, playSound);

    function playSound (e:MouseEvent):void{
try {
    ExternalInterface.call("countdown");
    } catch(e:Error) {
    trace(e)
    }
//ExternalInterface.call("countdown");
gotoAndStop(2);
var soundClip:Sound; 
var soundChannel:SoundChannel = new SoundChannel();

function init() {
    soundClip = new Sound();
    soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);
    soundClip.addEventListener(Event.COMPLETE, soundLoaded);

    var req:URLRequest = new URLRequest(audioTrackPath);
    var context:SoundLoaderContext = new SoundLoaderContext(1000, true);
    soundClip.load(req,context);
    //soundChannel = soundClip.play();
}

init();

function soundLoaded(e:Event) {
    soundChannel = soundClip.play();

}

function soundLoading(e:ProgressEvent) {
// preloader information goes here
    trace(String(int(100*e.bytesLoaded / e.bytesTotal))+"%");
}

stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
    function stopSound (e:MouseEvent):void{
    gotoAndStop(1);
    soundChannel.stop();
}   
}

我已经谷歌搜索了3天了,但我似乎无法找到答案......

4 个答案:

答案 0 :(得分:1)

您应该声明问题是ExternalInterface.call()首先不起作用。

使用外部接口调用(如

)构建一个简单的项目
if(ExterlInterface.available){
    ExternalInterface.call('alert','ExterlInterface.available');
}

在第一帧(如果您使用闪光灯)并发布

它将为您提供以下html

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ei</title>
</head>
<body bgcolor="#ffffff">
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="550" height="400" id="ei" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="movie" value="ei.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />  <embed src="ei.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="ei" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
    </object>
</body>
</html>

如果失败了,那么这是你的浏览器造成的麻烦,对我来说很好。 如果它正常工作那么你的HTML很糟糕。

答案 1 :(得分:0)

好像你在对象定义中缺少movie参数。不同的浏览器使用不同的标签从中获取闪存信息 - 一些使用嵌入,一些使用对象。

试试这个html

    <object type="application/x-shockwave-flash" classid="bla" width="18" height="30"               id="myFlashMovie"> 
<param name="movie" value="player.swf">
<param name="wmode" value="opaque" />   
<param name="FlashVars" value="mp3.mp3" />
<embed type="application/x-shockwave-flash" width="18" height="30"      src="player.swf" id="flashObj" FlashVars="audioTrackPath=mp3.mp3" />
    </object>

我还会将文件引用直接放入url

<param name="movie" value="player.swf?audioTrackPath=mp3.mp3">

答案 2 :(得分:0)

替换它:

<param name="FlashVars" value="mp3.mp3" />

有了这个:

<param name="FlashVars" value="audioTrackPath=mp3.mp3" />

FlashVars是名称 - 值对。

Ognjen,不要采取错误的方式,但作为建议,而不是“谷歌3天”,下次你可以把一些努力用于校对代码。

答案 3 :(得分:0)

看起来您应该将您的classid从bla更改为clsid:d27cdb6e-ae6d-11cf-96b8-444553540000
还要检查我的类似opensource project(但是,它在IE 6中不起作用,但在新版本中没有问题)