为什么我不能得到的Javascript去跟动作 [英] Why can't I get Javascript to Talk to ActionScript
问题描述
我有一个播放音乐一个非常简单的Flash程序。它由一个播放暂停按钮和一个计时器以显示歌曲的当前位置。我试图使人们有可能暂停或使用常规的表单按钮播放歌曲。
I have a very simple flash program that plays music. It consists of a play pause button and a timer that shows the current position of the song. I'm trying to make it possible to pause or play the song using a regular form button.
<div class="musicplayer_playpause">
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','65','height','68','src','player','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','id','flashobject','movie','player','flashvars','id=<?=$cur_songid;?>&type=<?=$_GET["type"];?>&csid=<?=$cur_songid;?>&l=<?=$Arrcntt+1;?>"' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" id="flashobject" width="65" height="68">
<param name="movie" value="player.swf" allowscriptaccess="always"/>
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="id" value="flashobject" />
<param name="swliveconnect" value="true" />
<embed src="player.swf" name="flashobject" width="65" height="68" quality="high" allowscriptaccess="always" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" ></embed>
</object>
</noscript></div>
下面是Javascript的功能,我把部分:
Here's the Javascript function, which I put in the section:
<script type="text/javascript">
function Pause() {
var flash = document.getElementById('flashobject');
flash.PlayPause;
}
</script>
最后这里是我使用的按钮:
And finally here's the button I'm using:
<form>
<input type="button" value="Play" name="Play" onClick="Pause();">
</form>
当我按一下按钮,Firefox的错误控制台说:Flash是空我在做什么错了?
When I click the button, Firefox's error console says "Flash is null" What am I doing wrong?
推荐答案
我不认为这是一个直接的解决你的问题,但我从经验中知道,使用
I don't think it's a direct solution to your problem, but I know from experience that using
var flash = document.getElementById('flashobject');
flash.PlayPause;
将不会显示在所有流行的浏览器相同的行为。您可以尝试使用下面的函数返回对象:
will not show the same behaviour in all popular browsers. you can try to use the following function to return the object:
function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
};
thisMovie('flashobject').PlayPause();
如果您但是使用jQuery,下面会做什么:
If you are using jQuery however, the following will do:
$("#flashobject")[0].PlayPause();
编辑:我发现thisMovie功能的更多更新的版本。我仍然建议jQuery的方式,虽然:)
edit: I found a more updated version of the thisMovie function. I would still recommend the jQuery way though :)
function getFlashMovieObject(movieName){
if(document.embeds[movieName])
return document.embeds[movieName];
if(window.document[movieName])
return window.document[movieName];
if(window[movieName])
return window[movieName];
if(document[movieName])
return document[movieName];
return null;
}
这篇关于为什么我不能得到的Javascript去跟动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!