...

View Full Version : missing var i think?



admhays
07-09-2009, 12:44 AM
I am using a bit off code I found from a source file and I think it was missing a var "req" on line 13 "snd.load(req, context)"

the player is located at www.strivingforcairo.com under the music tab. I am trying to just get one song to play pause and stop. I have not added the text title yet. I have created a single mc and duplicated it for each track. I need help loading the song from the library for each individual track mc

Thanks!

here is the AS:
stop();
// Create the sound object
var snd:Sound = new Sound();
// Assign a var name for the sound channel
var channel:SoundChannel;
// Initialize the pause position
var pausePosition:int = 0;
// Boolean value for button functions, to switch in the conditionals
var isPlaying:Boolean = false;
// Set the play buffer to 5 seconds, you can adjust this
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
// Load the requested URL sound into the snd var, along with context
//This line of code is generating the error
snd.load(req, context);
// Create the play channel using snd
channel = snd.play(); // Start playing
// Set "isPalying" to true initially
isPlaying = true;


// Listen for the onPlaybackComplete function directly below

////////////////////////////////////////////////////////////////////////////////////

// Play Function //////////////////////////////////////////////////////
function playSound(event:MouseEvent):void {

if (isPlaying == false) {

channel = snd.play(pausePosition);
isPlaying = true;
}

}
////////////////////////////////////////////////////////////////////////////////////

// Stop Function //////////////////////////////////////////////////////
function stopSound(event:MouseEvent):void {

channel.stop();
pausePosition = 0;
isPlaying = false;
}

// Pause Function //////////////////////////////////////////////////////
function pauseSound(event:MouseEvent):void {

pausePosition = channel.position;
channel.stop();
isPlaying = false;
}
////////////////////////////////////////////////////////////////////////////////////

// Button Listeners ///////////////////////////////////////////////////////////////////////
playBtn.addEventListener(MouseEvent.CLICK, playSound);
stopBtn.addEventListener(MouseEvent.CLICK, stopSound);
pauseBtn.addEventListener(MouseEvent.CLICK, pauseSound);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////// VOLUME Up and Down CODE //////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Add listener to trigger [onEnterFrame] function below
addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(event:Event):void {

// Get full time
var tallytime = (snd.length/1000);
var totalmins:Number = Math.floor(tallytime /60);
var totalsecs = Math.floor (tallytime) % 60;
if (totalsecs < 10){
totalsecs = "0" + totalsecs;
}
displayFullTime.text = ( " " + totalmins+ ":" + totalsecs);

// End get Full time
// Get playing time
var totalSeconds:Number = channel.position/1000;
var minutes:Number = Math.floor(totalSeconds /60);
var seconds = Math.floor (totalSeconds) % 60;
if (seconds < 10){
seconds = "0" + seconds;
}
displayTime.text = ( " " + minutes+ ":" + seconds);
// End get playing time

/// progress bar code...
var estimatedLength:int = Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal));
var playbackPercent:uint = 100 * (channel.position / estimatedLength );
// I want my position bar to be 200 pixels wide on completion so I multiply the percentage x 2
positionBar.width = playbackPercent * 2;

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum