A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Flash CS3 - AS 2.0 - Can't get sound to play in any scene after the 1st scene

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    1

    Unhappy Flash CS3 - AS 2.0 - Can't get sound to play in any scene after the 1st scene

    Hey guys, I'm having trouble getting any sound to play in my second scene. I'm using actionscript in the first scene to fade in the music, then fade it out after they click the button.

    Here's the code on layer 1:

    Actionscript Code:
    music = new Sound();
    music.attachSound("background");
    music.setVolume(0);
    music.start(0,1);

    vol = 0;
    // set another variable named 'fade', putting a setinterval function in it
    fade = setInterval(fadeIn,100);
    // set the initial fade in function
    function fadeIn() {
            // fade the sound in with an increment of 3 in the variable 'vol'
            vol += 3;
            music.setVolume(vol);
            // put an if condition to restrict the increment in volume after it reaches to 100
            if (vol>=100) {
                    clearInterval(fade);
                    // create the 'step' variable
                    step = 3;
                    // create the 'fade' variable
                    fade2 = 0;
            }
    }
    // create the fade in and out function
    // function executed on onEnterFrame
    _root.onEnterFrame = function() {
            // set fade out
            if (fade2 == 1) {
                    vol = vol-step;
                    if (vol<0) {
                            vol = 0;
                    }
                    music.setVolume(vol);
                    // set fade in
            } else {
                    vol = vol+step;
                    if (vol>=100) {
                            vol = 100;
                    }
                    music.setVolume(vol);
            }
    }

    This code does exactly what it should (fades the music in, then fades it out when the user clicks the button)

    Here's the code for the button:
    Actionscript Code:
    stop();

    play_btn.onRelease = function(){
            (_root.fade2=!_root.fade2) ? 0 : 1;
        _root.gotoAndPlay(241); //Fades out and ends, going to scene 2
    }

    Problem: I tried adding a sound to the stage in scene 2 but nothing plays when i test the movie, expect for the music in scene 1. I tried creating another sound object in the first frame of scene 2 but i get the same result. Any ideas why it won't work?

  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    26
    gees im new to flash im using as2 and i only need a simple code to do that i dont understand any of yours hehe might this be helpfull? the newb way il gues?

    on(press)
    {
    stopAllSounds();
    }

    then double click your button and you should see 4 frames with up down over and hit or something(only works if its a button! ofcourse:P)
    make a frame @ "hit" and drag your music piece from library into your button while your on the "hit" frame

    on(release)
    {
    gotoAnd.......("...")
    }

    so thats how i stop the first piece of music and activate the 2nd without needing to change frames and without minding you will change to another frame

    hope my way will be any helpfull to your problem:P

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    @TheFlash07

    Instead of:
    music = new Sound();

    I suggest using:
    music = new Sound(someMovie);

    It will attach the Sound object to a specific MovieClip. You'll have more control overall.

    In your next Scene, you can attach a Sound again to another instance. Make sure that instance is present on the timeline on the frame where you pt the code.

    gparis

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center