给Flex写个简单的背景音乐播放

给Flex写个简单的背景音乐播放

    播放时:
    暂停时:



      简单的播放按钮
<mx:Button x="865" y="33"  id="playerbutton" width="48" height="48" icon="{play1}"  click="misicPlay(event)"/>


     按钮的播放事件
                      //播放状态时的图标显示
[Bindable]
[Embed(source="images/icon/200.png")]
public var play1:Class;
//暂停
状态时的图标显示
[Bindable]
[Embed(source="images/icon/199.png")]
public var play2:Class;
private var snd:Sound;
private var channel:SoundChannel;
private var playStatus:Number = 1;
protected function misicPlay(event:MouseEvent):void
{
if(playStatus==1){
snd = new Sound(new URLRequest("1.mp3"));
channel = snd.play();
 playerbutton.setStyle("icon",play2);
 playStatus = 0;
}
else if(playStatus==0)
{
playerbutton.setStyle("icon",play1);
channel.stop();
playStatus = 1;
}
}

你可能感兴趣的:(给Flex写个简单的背景音乐播放)