Audio 使用JavaScript播放Flash音频

Audio 使用JavaScript播放Flash音频,audio,flash-javascript-api,Audio,Flash Javascript Api,我只需要一些关于如何在Javascript上单击播放音频剪辑的指导。为了在flash和Javascript之间来回对话,您应该使用flash.external.ExternalInterface类和回调 闪光as3 HTML页面 var-swf; //等待页面加载完成 window.onload=init; //初始化swf变量,其中mySWF是页面上swf对象的id 函数init(){ swf=document.getElementById(“mySWF”); } //在swf上调用我们的外

我只需要一些关于如何在Javascript上单击播放音频剪辑的指导。

为了在flash和Javascript之间来回对话,您应该使用flash.external.ExternalInterface类和回调

闪光as3 HTML页面

var-swf;
//等待页面加载完成
window.onload=init;
//初始化swf变量,其中mySWF是页面上swf对象的id
函数init(){
swf=document.getElementById(“mySWF”);
}
//在swf上调用我们的外部函数
函数playSound(){
播放声音();
}

请原谅我的任何错误,代码未经测试,但应该给您正确的想法。

为了从flash到javascript来回对话,您应该使用flash.external.ExternalInterface类和回调

闪光as3 HTML页面

var-swf;
//等待页面加载完成
window.onload=init;
//初始化swf变量,其中mySWF是页面上swf对象的id
函数init(){
swf=document.getElementById(“mySWF”);
}
//在swf上调用我们的外部函数
函数playSound(){
播放声音();
}

请原谅我的任何错误,代码未经测试,但应该会给您正确的想法。

请参阅ActionScript中有关ExternalInterface的文档:请参阅ActionScript中有关ExternalInterface的文档:
import flash.external.ExternalInterface;
import flash.net.URLRequest;

//Create the javascript "playSound" on the swf object
ExternalInterface.addCallback("playSound", playSound);

//Create our sound object
var sound:Sound = new Sound;
//Load my.mp3 into our sound object
sound:Sound .load(new URLRequest("my.mp3"));

function playSound(){
    sound.play();
}
<script language="javascript">
    var swf;

    //Wait for page load to complete
    window.onload = init;

    //initialize our swf variable where mySWF is the id of the swf object on the page
    function init(){
        swf = document.getElementById("mySWF");
    }

    //call our external function on the swf
    function playSound(){
        swf.playSound();
    }
</script>