[转]flex中嵌入mp3声音文件

[url]http://www.it118.org/specials/be5aa227-758a-4292-a143-5d0de10556fb/e63a3d74-0078-4c71-b348-33522564d843.htm[/url]


您可以在 Flex 应用程序中通过使用 [Embed] 元数据标签嵌入 MP3 文件并播放它。

注意: 记住嵌入的声音文件会成为您的应用程序 (最终的 SWF 文件) 的一部分, 而 MP3 文件会很大, 从而会使您的应用程序变得很大并会对应用程序的下载速度产生负面影响。

此实例将该 MP3 的一个新实例创建为一个 SoundAsset。它使用 SoundAsset 类的 play() 方法来播放 MP3 文件的实例, 并存储返回的 SoundChannel 对象, 从而您可以稍后调用 SoundChannel 对象的 stop() 方法以结束播放。






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
{

// Make sure we don't get multiple songs playing at the same time
stopSound();

// Play the song on the channel
channel = mySong.play();
}

public function stopSound():void
{

// Stop the channel, but only if it exists
if ( channel != null ) channel.stop();
}

]]>











Pie-Yan-Knee Written and Performed by: Derek R. Audette (c) 2004 (Creative Commons Attribution License)]]>




你可能感兴趣的:(FLEX)