开发者

Cannot get JS to trigger As3 function in swf

Desperately need help and would be gretaful if someone could see if they can find what is wrong.

I am trying to trigger a swf movie embedded in web page by using a js function. This is a dry run using sample code I have found, i eventually just want the movie to play and stop via js instructions, when clicking an a href. Website is http://simplywebdzine.com/ASJS_test.html

The as3 code in the swf is:

import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str):void {
trace(str);
}

THANK YOU

Adding full 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=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function setCurrentPage(newPage) {
    currentPage = newPage;
    SendDataToFlashMovie(newPage);
}
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 SendDataToFlashMovie(newPage){
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.sendTextToFlash(newPage);
}

 </script>
 </head>
<body>

<a href="#" onClick="setCurrentPage('Home')">Home</a>

    <object height="250" width="380" id="myFlashMovie"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash
/swflash.cab#version=8"      classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param value="myFlashMovie.swf" name="movie">
<param value="high" name="quality">
<param value="transparent" name="wmode">
<param value="#FFFFFF" name="bgcolor">
<param value="true" name="allowFullScreen">
<param value="true" name="swLiveConnect">
<param value="always" name="allowScriptAccess">

 <embed height="250" align="middle" width="380" src="myFlashMovie.swf" quality="high" 
 pluginspage="http://www.macromedia.com/go/getflashplayer" play="false"
 loop="false"      scale="showall" wmode="transparent" devicefont="false"
 bgcolor="#000000" menu="true" allowfullscreen="false" allowscriptaccess="always"
 salign="" type="application/x-shockwave-flash" name="myFlashMovie">

</object></body&开发者_运维知识库gt;
</html>


Make sure you add the allow script access param in your flash embed (normally that's the problem)

<param name="allowScriptAccess" value="always" />


Looks like you have a typo in the html code you linked to. You have this code:

<a href onclick="javascript:SendDahMovie();">trigger</a> 

But the JS function you defined is:

function SendDataToFlashMovie(newPage){
    var flashMovie=getFlashMovieObject("myFlashMovie");
    flashMovie.sendTextToFlash(newPage);
}

Every time you click on the trigger link, no only your function is not called, but also the page reloads. So try fixing this name mismatch.

PS: By the way, your code actually works.

I ran this JS code from firebug:

SendDataToFlashMovie('testing');

And I can see the trace in flashlog.txt.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜