开发者

Problem getting Javascript to work with SWF file using ExternalInterface

开发者 https://www.devze.com 2023-01-20 09:25 出处:网络
I have a SWF file emedded withing a HTML page. Trying to do a simple operation - go to and play certain frame in SWF using javascript. I\'m using ExternalInterface to do this but for the life of me ca

I have a SWF file emedded withing a HTML page. Trying to do a simple operation - go to and play certain frame in SWF using javascript. I'm using ExternalInterface to do this but for the life of me can't get the two to communicate.

I add all the code but when clicking on the link which calls javascript, it says my flash object is undefined?

Here's the ActionScript code:

import flash.external.*;

function getFromJavaScript(frame:int):void 
{
 gotoAndPlay(frame);
}

ExternalInterface.addCallback("sendtoFlash",getFromJavaScript);

Here's the javascript:

function getFlashMovieObject(movieName){
if (window.document[movieName]){
    return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1){
    if (document.embeds && document.embeds[movieName])
        return document.embeds[movieName];
}
else{
    return document.getElementById(movieName);
}
}

function sendtoSwf(numb)
{
  var flashMovie = getFlashMovieObject("tour-flash");
  flashMovie.sendToFlash(numb);
}

And here is the embedded SWF:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="335" id="tourFlash" align="middle">
<param name="movie" value="/media/Assets/Flash/tourFlash.swf" />
<param name开发者_高级运维="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="/media/Assets/Flash/tourFlash.swf" width="600" height="335">
  <param name="movie" value="/media/Assets/Flash/tourFlash.swf" />
  <param name="quality" value="high" />
  <param name="bgcolor" value="#ffffff" />
  <param name="play" value="true" />
  <param name="loop" value="true" />
  <param name="wmode" value="window" />
  <param name="scale" value="showall" />
  <param name="menu" value="true" />
  <param name="devicefont" value="false" />
  <param name="salign" value="" />
  <param name="allowScriptAccess" value="sameDomain" />
<!--<![endif]-->
  <a href="http://www.adobe.com/go/getflash">
 <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
  </a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>

Any ideas? I'm totally stumped! For an example of problem, have a look here: http://www.onehealthfitness.com.au/get-started/virtual-tour.aspx

Thanks :)


Seems like you are using the wrong value in the getFlashMovieObject("tour-flash") call, there is no object named "tour-flash" in your code, is there?

Besides that, I would recommend that you add a mute button, so a visitor can turn of the sound. I tend to leave pages that plays sound I can't stop.


Lars is right. Besides, you ignore the firefox situation. I think you need to add the "embed" in the html.

Here is the official demo of "ExternalInterface":

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html#includeExamplesSummary

0

精彩评论

暂无评论...
验证码 换一张
取 消