简体   繁体   中英

flash as3 player in IE

I am trying to create a simple audio flash player, that calls a js function on click, it works perfectly in all browsers, except IE. i cant figure out what seems to be the problem!

here is 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>

and here is as:

    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();
}   
}

I have been Googling for 3 days now, but I can't seem to find an answer...

You should have stated that the issue is ExternalInterface.call() not working in the first place.

Build a simple project with just external interface call like

if(ExterlInterface.available){
    ExternalInterface.call('alert','ExterlInterface.available');
}

on the first frame (if you are using flash) and publish it

it will give you following 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>

If that fails, then it's your browser causing trouble, works fine for me. If it is working then your html is bad.

Seems like you are missing movie parameter in object definition. Different browsers use different tags from which they pick up flash information - some use embed, some use object.

try this 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>

i would also put the file reference directly in to the url

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

Replace this:

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

With this:

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

FlashVars are name-value pairs.

Ognjen, don't take this the wrong way, but as an advice, instead of "googleing for 3 days", next time you could put some of that effort into proofreading the code.

looks like you should change your classid from bla to clsid:d27cdb6e-ae6d-11cf-96b8-444553540000
also check my similar opensource project (which, however doesn't work in IE 6, but fine in newer versions)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM