In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

SiONを使って歌詞とメロディを出す

Get Adobe Flash player
by HaraMakoto 03 Oct 2009
/**
 * Copyright HaraMakoto ( http://wonderfl.net/user/HaraMakoto )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/20pq
 */

package
{
    import com.bit101.components.*;
    
    import flash.display.Sprite;
    import flash.events.*;
    
    import org.si.sion.*;
    import org.si.sion.events.SiONEvent;
    import org.si.sion.events.SiONTrackEvent;
    import org.si.sion.utils.SiONPresetVoice;
    [SWF(width = "465", height = "465", backgroundColor = "#000000")]
    
    public class SionVoice extends Sprite {
    	//歌詞とメロディのXML
    	private var LylicXML:XML = XML('<items>' + 
    			'<item lyrics="きらきらひかる" code="ccggaag2" />' + 
    			'<item lyrics="夜空の星よ" code="ffeeddc2" />' + 
    			'<item lyrics="まばたきしては" code="ggffeed2" />' + 
    			'<item lyrics="みんなをみてる" code="ggffeed2" />' + 
    			'<item lyrics="きらきらひかる" code="ccggaag2" />' + 
    			'<item lyrics="夜空の星よ" code="ffeeddc2" />' + 
    			'</items>');
        public var driver:SiONDriver = new SiONDriver();
        public var presetVoice:SiONPresetVoice = new SiONPresetVoice();
        public var voice1:SiONVoice;
        public var mainMelody:SiONData;
        private var LyricCounter:Array = new Array();
        
        private var counter:int = 0;
        private var lCounter:int = 0;
        
        //コンストラクタ
        function SionVoice() {
        	//XMLからMMLを取り出す
	    	var MerodyStr:String;
	    	for each(var merObj:Object in LylicXML.item) {
	    		MerodyStr += String(merObj.@code) + " ";
	    	}
            mainMelody = driver.compile("%t0,1,1,t120 l4 ["+MerodyStr+" ]1");
            voice1 = presetVoice["valsound.piano8"];
	    	new PushButton(this,  20, 50, "Play Melody", _play_preset1);
            driver.addEventListener(SiONTrackEvent.NOTE_ON_STREAM, NoteOnEvent);
           
            driver.play();
            GetcountCode(LylicXML);
        }
        
        private function GetcountCode(xml:XML):void {
        	var s:int = 0;
        	LyricCounter.push(s);
        	for(var i:int=0; i<xml.children().length()-1; i++) {
        		s += String(xml.item[i].@code).length-1;
        		LyricCounter.push(s);
        	}
        }
        
        private function NoteOnEvent(e:SiONTrackEvent):void {
        	if(counter==LyricCounter[lCounter]) {
        		var ono:onomatop = new onomatop();
        		this.addChild(ono);
        		ono.makeText(String(LylicXML.item[lCounter].@lyrics));
        		ono.x = 100 + 100 * Math.random();
        		ono.y = 100 + 100 * Math.random();
        		
        		lCounter++;
        	}
        	counter++;
        }
       
        
        private function _play_preset1(e:MouseEvent) : void {
	        counter = lCounter = 0;
            driver.sequenceOn(mainMelody, voice1, 0, 0, 2);
            driver.addEventListener(SiONTrackEvent.NOTE_ON_FRAME, NoteOnEvent);
        }
    }
}

	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.display.Bitmap;
	import caurina.transitions.Tweener;
	import caurina.transitions.Equations;
	

class onomatop extends Sprite {
	private var textField:TextField;
	private var textFormat:TextFormat;
	private var textBitmapData1:BitmapData;
	private var rect:Rectangle;
	private var textBitmapData2:BitmapData;
	private var bmp:Bitmap = new Bitmap();
	
	public function onomatop() {
		
	}
	public function makeText(LETTER:String):void {
		// 表示文字列の TextField
		textField = new TextField();
		textFormat = new TextFormat(null, 30, 0xFFFFFF);
		textFormat.letterSpacing = -2;
		textField.defaultTextFormat = textFormat;
		textField.text = LETTER;
		textField.autoSize = TextFieldAutoSize.LEFT;
		// TextField を BitmapData 化
		textBitmapData1 = new BitmapData(textField.width, textField.height, true, 0x00000000);
		textBitmapData1.draw(textField, new Matrix(1, 0, 0, 1, -2, -2));
		rect = textBitmapData1.getColorBoundsRect(0xFF000000, 0x00000000, false);
		textBitmapData2 = new BitmapData(rect.width + 4, rect.height + 4, true, 0x00000000);
		textBitmapData2.draw(textBitmapData1, new Matrix(1, 0, 0, 1, -rect.x + 2, -rect.y + 2));
		textBitmapData1.dispose();
		addChild(bmp);
		bmp.bitmapData = textBitmapData2;
		textBitmapData1 = null;
		
		fadeOut();
	}
	
	public function fadeOut():void {
		Tweener.addTween(this,{alpha:0, time:1, delay:2, transition:Equations.easeOutQuint, onComplete:destroy});
	}
	
	public function destroy():void {
		bmp.bitmapData = null;
		removeChild(bmp);
		bmp = null;
		textBitmapData2.dispose();
		textField = null; textFormat = null;
		rect = null; textBitmapData2 = null;
	}
}