Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post

    missing var i think?

    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;

    }
    Last edited by admhays; 07-10-2009 at 05:45 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •