0

我正在使用下面的代码来加载外部 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 文件的下拉菜单列表的路径。

4

1 回答 1

0

您必须ExternalInterface.addCallback在您的 AS 中使用并从 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());
});

不要忘记将 / 设置allowscriptaccessobject正确embed的值,以便页面可以与 flash 对象通信

于 2012-11-12T20:46:32.330 回答