1 音乐系统
这里我实现了包括自动音乐循环 音乐淡入 音乐淡出 调节音量 随机切换音乐的功能
package
{
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import fl.transitions.Tween;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
import com.greensock.TweenLite;
import com.greensock.TweenMax;
import flash.utils.getDefinitionByName;
public class BackgroundMusic
{
private var sound0:Sound;
private var soundct:SoundChannel=new SoundChannel();
public var lastid:int = 0;
public function BackgroundMusic()
{
}
public function playbgsound(type:int,notcontinuer:Boolean):void
{
lastid = getmusicid(type);
var symbolName:String = "BgSound" + lastid.toString();
var symbolClass:Class = getDefinitionByName(symbolName) as Class;
sound0 = new symbolClass ;
soundct = sound0.play();
if(notcontinuer)
{
TweenMax.fromTo(soundct,10, {volume:0}, {volume:1});
}
soundct.addEventListener(Event.SOUND_COMPLETE,onComplete1);
}
public function setvolume(t1:Number):void
{
var transforme:SoundTransform = new SoundTransform(t1,0);
SoundMixer.soundTransform = transforme;
}
public function stopSound():void
{
soundct.stop();
lastid=0;
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
}
public function stopbgsound():void
{
TweenMax.to(soundct,6, {volume:0});
lastid=0;
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
}
private function onComplete1(e:Event):void
{
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
playbgsound(Main.sceneid,false);
}
public function changemusicrd():void
{
changemusic(Math.floor(Math.random() * 15 + 1))
}
public function changemusic(tt:int):void
{
stopSound()
playbgsound(tt,true)
}
}
}
这里我实现了包括自动音乐循环 音乐淡入 音乐淡出 调节音量 随机切换音乐的功能
package
{
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import fl.transitions.Tween;
import flash.media.SoundTransform;
import flash.media.SoundMixer;
import com.greensock.TweenLite;
import com.greensock.TweenMax;
import flash.utils.getDefinitionByName;
public class BackgroundMusic
{
private var sound0:Sound;
private var soundct:SoundChannel=new SoundChannel();
public var lastid:int = 0;
public function BackgroundMusic()
{
}
public function playbgsound(type:int,notcontinuer:Boolean):void
{
lastid = getmusicid(type);
var symbolName:String = "BgSound" + lastid.toString();
var symbolClass:Class = getDefinitionByName(symbolName) as Class;
sound0 = new symbolClass ;
soundct = sound0.play();
if(notcontinuer)
{
TweenMax.fromTo(soundct,10, {volume:0}, {volume:1});
}
soundct.addEventListener(Event.SOUND_COMPLETE,onComplete1);
}
public function setvolume(t1:Number):void
{
var transforme:SoundTransform = new SoundTransform(t1,0);
SoundMixer.soundTransform = transforme;
}
public function stopSound():void
{
soundct.stop();
lastid=0;
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
}
public function stopbgsound():void
{
TweenMax.to(soundct,6, {volume:0});
lastid=0;
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
}
private function onComplete1(e:Event):void
{
soundct.removeEventListener(Event.SOUND_COMPLETE,onComplete1);
playbgsound(Main.sceneid,false);
}
public function changemusicrd():void
{
changemusic(Math.floor(Math.random() * 15 + 1))
}
public function changemusic(tt:int):void
{
stopSound()
playbgsound(tt,true)
}
}
}