Tuesday, March 17, 2009

Lesson_11: MP3 & Sound()

This week we will be playing external mp3 files using some Actionscript.

// ****************
// * FRAME SCRIPT *
// ****************
// Setting Up The Sound Object //
// 1. Assign the file folder and filename to variables
// 2. Create a new sound object
// 3. Load the sound file
// 4. Initialize the start position to 0
// 5. Start Streaming the sound file (true – streaming, false – event)
songFolder = "songs/";
songFilename = "patsong2007.mp3";
playThisSong = new Sound();
playThisSong.loadSound(songFolder + songFilename, true);

var whereAmI:Number = 0;
playThisSong.start(0, 1);


// *******************
// * Pause BUTTON *
// *******************
on(release) {
// Where Am I when I paused?
// 1. The position is stored in variable whereAmI
var whereAmI:Number = playThisSong.position/1000;

// 2. The song is set to stop playing
playThisSong.stop();

// 3. Trace to the Output Window WhereAmI
trace(whereAmI+newline);
}


// ***************
// * Play BUTTON *
// ***************
on (release) {

// Start playing the song from the most current position
playThisSong.start(whereAmI, 1);
}


// *******************
// * Rewind BUTTON *
// *******************
on (release) {
// reset position to beginning
var whereAmI:Number = 0;
}

No comments: