【问题标题】:Flex 4 - Embedding Multiple MP3'sFlex 4 - 嵌入多个 MP3
【发布时间】:2012-01-16 09:23:42
【问题描述】:

我有一个嵌入在带有开始和停止按钮的 Flex 应用程序中的 mp3。使用此代码...

<fx:Script>
<![CDATA[ 
import mx.core.SoundAsset; 
import flash.media.*; 

[Embed(source="assets/pie-yan-knee.mp3")] 
[Bindable] 
public var Song:Class; 

public var mySong:SoundAsset = new Song() as SoundAsset; 
public var channel:SoundChannel;

public function playSound():void
{ 
  stopSound(); 
  channel = mySong.play();
}

public function stopSound():void
{
  if ( channel != null ) channel.stop();
} 
]]>
</fx:Script> 

<s:HGroup> 
<s:Button label="play" click="playSound();"/> <s:Button label="stop"
  click="stopSound();"/> 
</s:HGroup>

不过,我希望有多个具有不同声音的实例。 我该怎么做?

【问题讨论】:

    标签: actionscript-3 apache-flex embed flex4.5 audio


    【解决方案1】:

    只需为每个单独的类引用:

    [Embed(source="assets/song1.mp3")] 
    [Bindable] 
    public var Song1:Class; 
    [Embed(source="assets/song2.mp3")] 
    [Bindable] 
    public var Song2:Class; 
    [Embed(source="assets/song3.mp3")] 
    [Bindable] 
    public var Song3:Class; 
    

    【讨论】:

    • 必须进行其他更改,我收到错误“-1151:与内部命名空间中的定义 sndChannel 存在冲突。”在所有的声音上。
    • 我做了一些其他的改变,现在它正在工作,所以你指出了我正确的方向。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2010-12-18
    • 2011-07-14
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多