SiON practice2
/**
* Copyright k2syndrome_g ( http://wonderfl.net/user/k2syndrome_g )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/2jKy
*/
// forked from k2syndrome_g's SiON practice1
package {
import flash.events.Event;
import flash.display.*
import org.si.sion.*;
import org.si.sion.events.*;
public class ABCSong extends Sprite {
//ドライバ
public var driver:SiONDriver=new SiONDriver();
//MML data
public var mainMelody:SiONData;
public function ABCSong() {
mainMelody=driver.compile("%t0,1,1 t100 l8 [ccggaag4 ffeeddc4 | [ggffeed4]2 ]2");
driver.addEventListener(SiONTrackEvent.NOTE_ON_FRAME,onNoteOn);
driver.addEventListener(SiONTrackEvent.NOTE_OFF_FRAME,onNoteOff);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
driver.play(mainMelody);
}
private function onNoteOn(e:SiONTrackEvent):void{
createNote(e.note);
}
private function onNoteOff(e:SiONTrackEvent):void{
}
private function createNote(num:int):Shape{
var shape:Shape=new Shape();
shape.graphics.beginFill([0xFF8080,0x80FF80,0x8080FF,0xFFFF80][int(Math.random()*4)]);
shape.graphics.drawCircle(0,0,Math.random()*20+10);
shape.graphics.endFill();
shape.x=(num-60)*30;
shape.y=300;
addChild(shape);
return shape;
}
private function onEnterFrame(e:Event):void{
var imax:int=numChildren;
for(var i:int=0;i<imax;i++){
var child:DisplayObject=getChildAt(i);
child.y-=2;
child.alpha*=0.98;
if(child.y<-30||child.alpha<0.1){
removeChild(child);
imax--;
i--;
}
}
}
}
}