Javascript 如何将*参数*从JS传递到AS3?
我的swf文件中有一个函数:playSound(),我可以通过jQuery调用它,如下所示:Javascript 如何将*参数*从JS传递到AS3?,javascript,jquery,flash,parameter-passing,Javascript,Jquery,Flash,Parameter Passing,我的swf文件中有一个函数:playSound(),我可以通过jQuery调用它,如下所示: $.talkToFlash("interfaceSounds").playSound(); 而“talkToFlash”只返回swf文件。这一部分在这里有很好的文档记录,可以很好地工作 但是,如何传递参数 我相信这将是: $.talkToFlash("interfaceSounds").playSound('swish.mp3'); 但是在AS3中我该怎么做呢 我试图修改我最初的工作职能: func
$.talkToFlash("interfaceSounds").playSound();
而“talkToFlash”只返回swf文件。这一部分在这里有很好的文档记录,可以很好地工作
但是,如何传递参数
我相信这将是:
$.talkToFlash("interfaceSounds").playSound('swish.mp3');
但是在AS3中我该怎么做呢
我试图修改我最初的工作职能:
function playSound() {
var s:swishSound = new swishSound;
var channel:SoundChannel = s.play();
}
ExternalInterface.addCallback("playSound", playSound);
为此:
function playSound(mp3file) {
trace(mp3file);
}
但是“mp3file”只是空的。我试过了
ExternalInterface.addCallback("playSound", playSound(mp3file));
和这个“主题”的其他变体,但似乎没有任何效果。我只是在这里挣扎,还是在这里挣扎?谢谢你的帮助。看来你就快到了。这里有一个修订。让我知道它是否有效
function playSound(mp3file::String) {
trace(mp3file);
}
ExternalInterface.addCallback("playSound", playSound);
另请参见:事实证明,这是正确的开始。错误在其他地方,我忘了嵌入字体:/ 然而,对于那些构建类似东西的人来说,这里是完整的代码。我也不确定我停止轨道的方法是否正确,因此任何改进都是最受欢迎的:) AS3: 在jQuery中:
// play a song
$.curPlay = '';
$(".song_play").click(function() {
var id = $(this).attr('id');
song = id.replace('play_', '');
if(song==$.curPlay){ // stop the current song if the play btn is clicked twice
$.stop_mp3();
$.curPlay = '';
return;
}
$.curPlay = song;
$.play_mp3(song);
});
$.play_mp3 = function(file){
$.stop_mp3();
$.talkToFlash("interfaceSounds").playTrack(file);
}
$.stop_mp3 = function(){
$.talkToFlash("interfaceSounds").stopAllTracks();
}
// movie referencer
$.talkToFlash = function(swfFile){
if (window.document[swfFile]) {
return window.document[swfFile];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1){
if (document.embeds && document.embeds[swfFile])
return document.embeds[swfFile];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(swfFile);
}
}
和HTML/PHP:
<div class='song_play' id='play_<?=$songID?>'>play</div>
<div class='song_play' id='play_<?=$songID?>'>play</div>
<?
$swf = "mp3_player.swf?".time();
$w = 1;
$h = 1;
$mp3Player = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8\"
codebase = \"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\"
width=\"$w\" height=\"$h\" id=\"interfaceSounds\" align=\"middle\">
<param name=\"allowScriptAccess\" value=\"always\" />
<param name=\"allowFullScreen\" value=\"false\" />
<param name=\"movie\" value=\"/assets/swf/$swf\" />
<param name=\"quality\" value=\"high\" />
<embed src=\"/assets/swf/$swf\" quality=\"high\" width=\"$w\"
height=\"$h\" name=\"interfaceSounds\" align=\"middle\"
allowScriptAccess=\"always\" allowFullScreen=\"false\"
type=\"application/x-shockwave-flash\"
pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />
</object>";
<?= $mp3Player ?>