root/as3/SiOPM/trunk/samples/Tutorials/FadeInOut.as

リビジョン 2697, 2.7 kB (コミッタ: keim, コミット時期: 3 年 前)

サウンドライブラリ SiON ver0.5.3 更新 tutrial 追加など

Line 
1 // Sample for fade-in and out.
2 package {
3     import flash.display.Sprite;
4     import flash.events.*;
5     import org.si.sion.*;
6     import org.si.sion.events.*;
7     import org.si.sion.utils.SiONPresetVoice;
8    
9    
10     public class FadeInOut extends Sprite {
11         // driver
12         public var driver:SiONDriver = new SiONDriver();
13        
14         // preset voice
15         public var presetVoice:SiONPresetVoice = new SiONPresetVoice();
16        
17         // voice for sampler "%10"
18         public var samplerVoice:SiONVoice = new SiONVoice(10);
19        
20         // MML data
21         public var drumLoop:SiONData;
22        
23         // constructor
24         function FadeInOut() {
25             // compile mml.
26             drumLoop = driver.compile("#EFFECT0{ws95lf4000}; %6@0o3l8$c2cc.c.; %6@1o3$rcrc; %6@2v8l16$[crccrrcc]; %6@3v8o3$[rc8r8]")
27            
28             // set voices of "%6@0-3" from preset
29             var percusVoices:Array = presetVoice["valsound.percus"];
30             drumLoop.setVoice(0, percusVoices[0]);  // bass drum
31             drumLoop.setVoice(1, percusVoices[27]); // snare drum
32             drumLoop.setVoice(2, percusVoices[16]); // close hihat
33             drumLoop.setVoice(3, percusVoices[21]); // open hihat
34            
35             // listen click
36             stage.addEventListener("click", _onClick);
37
38             // listen FADE_PROGRESS and FADE_*_COMPLETE
39             driver.addEventListener(SiONEvent.FADE_PROGRESS,     _onFading);
40             driver.addEventListener(SiONEvent.FADE_IN_COMPLETE,  _onFadeInComplete);
41             driver.addEventListener(SiONEvent.FADE_OUT_COMPLETE, _onFadeOutComplete);
42            
43             // stop when fadeout is completed.
44             driver.autoStop = true;
45            
46             // ...and play it
47             driver.play(drumLoop);
48            
49             // fade-in in 5[sec]
50             driver.fadeIn(5);
51         }
52        
53        
54         private function _onClick(e:Event) : void
55         {
56             // fade-out in 5[sec] when fader is not active. The fader is active while fading.
57             if (!driver.fader.isActive) driver.fadeOut(5);
58         }
59        
60        
61         // dispatch while fading
62         private function _onFading(e:SiONEvent) : void
63         {
64             // driver.fader.value refers the fading volume ranged between 0-1.
65             trace(driver.fader.value);
66         }
67        
68        
69         // dispatch when finished to fade in.
70         private function _onFadeInComplete(e:SiONEvent) : void
71         {
72             trace(">fade in");
73         }
74        
75        
76         // dispatch when finished to fade out.
77         private function _onFadeOutComplete(e:SiONEvent) : void
78         {
79             trace(">fade out");
80         }
81     }
82 }
83
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。