我使用下面的代码加载一个外部mp3文件:
//Create an instance of the Sound class
var soundClip:Sound=new Sound();
//Create a new SoundChannel Object
var sndChannel:SoundChannel=new SoundChannel();
//Load sound using URLRequest
soundClip.load(new URLRequest("namesounds/agamemnonas.mp3"));
//Create an event listener that wll update once sound has finished loading
soundClip.addEventListener(Event.COMPLETE,onComplete,false,0,true);
function onComplete(evt:Event):void {
//Play loaded sound
sndChannel=soundClip.play();
}在我的html中也有一个下拉列表:
<select name="sounds" id="sounds">
<option value="sounds/eden.mp3" selected="selected">eden</option>
<option value="sounds/zeus.mp3">zeus</option>
<option value="sounds/earth.mp3">earth</option>
</select>是否可以将下拉菜单中的路径发送到flash文件?例如:
//Load sound using URLRequest
soundClip.load(new URLRequest("namesounds/agamemnonas.mp3"));URLRequest必须是我的.php文件中下拉菜单列表中的路径。
发布于 2012-11-13 04:46:32
您必须在AS中使用ExternalInterface.addCallback,并从javascript调用该函数
AS3
ExternalInterface.addCallback("loadSoundClip", loadSoundClip);
function loadSoundClip(mp3File:String):void{
soundClip.load(new URLRequest(mp3File));
}纯Javascript
// This is the <select>
var sounds = document.getElementById('sounds');
// This is the <object>/<embed>
var flashObject = document.getElementById('flashObject');
sounds.onchange = function(){
flashObject.loadSoundClip(sounds.options[sounds.selectedIndex].value);
};或
jQuery
// This is the <select>
var sounds = $('#sounds');
// This is the <object>/<embed>
var flashObject = $('#flashObject');
sounds.on('change', function(){
flashObject[0].loadSoundClip($(this).val());
});不要忘记将flash object /object的object设置为正确的值,以便页面可以与 object进行通信
https://stackoverflow.com/questions/13351275
复制相似问题