简体   繁体   English

AS3声音加载

[英]AS3 sound loading

I am using the code below to load an external mp3 file: 我正在使用下面的代码加载外部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();
}

Also in my html I have a drop down list: 同样在我的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>

Is it possible to send a path from a drop down menu to a flash file? 是否可以从下拉菜单发送路径到Flash文件? For example: 例如:

//Load sound using URLRequest
soundClip.load(new URLRequest("namesounds/agamemnonas.mp3"));

The URLRequest must be the path from drop down menu list from my .php file. URLRequest必须是我的.php文件中下拉菜单列表中的路径。

You'll have to use ExternalInterface.addCallback in your AS and call that function from javascript 您必须在AS中使用ExternalInterface.addCallback并从javascript调用该函数

AS3 AS3

ExternalInterface.addCallback("loadSoundClip", loadSoundClip);
function loadSoundClip(mp3File:String):void{
    soundClip.load(new URLRequest(mp3File));
}

Pure Javascript 纯Java脚本

// 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);
};

OR 要么

jQuery 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());
});

Don't forget to set your allowscriptaccess of the object / embed to the correct value so the page can communicate with the flash object 不要忘记将对objectallowscriptaccess设置/ embed到正确的值,以便页面可以与Flash对象通信

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM