Tuesday, 18 October 2011

useful bits of code

found these in the Sound Programming Video Textbook section of http://www.developphp.com/list_flash_video.php


Define the sound object and the sound channel:


var snd:Sound = new Sound();
var req:URLRequest = new URLRequest("mp3_files/raquel my body.mp3");
snd.load(req);
var channel:SoundChannel;
channel = snd.play();
status_txt.text = "The song is now playing";

This could be useful, as it allows streaming of external mp3 files. The dude doing the tutorial says that having whole songs in your .fla file can greatly increase its size, along with that of its .swf file. However my idea depends heavily on the clips syncing up perfectly, and varying loading/buffering times could affect this.



Enter Frame Event:

addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
    
leftpeak_txt.text = ""+(Math.round(channel.leftPeak * 100));
rightpeak_txt.text = ""+(Math.round(channel.rightPeak * 100));
leftBar.height = (Math.round(channel.leftPeak * 100));
rightBar.height = (Math.round(channel.rightPeak * 100));

}

Initiates a function every time the movie reaches the frame the actionscript is in. In a one-frame clip this will correspond to the framerate.


Sound completion event function and its listener

channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
    removeEventListener(Event.ENTER_FRAME, onEnterFrame);
status_txt.text = "The song is over";
}

Can be used to start another sound clip immediately after one finishes.

No comments:

Post a Comment