A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: need help with cs3 flash cs3 with adding multiple songs and a skip button

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    4

    need help with cs3 flash cs3 with adding multiple songs and a skip button

    Hello I am new to the Action Script world. I am currently making an interactive cd-rom for my school project.
    It is action script 3.
    As of right now I have a button that plays a song and I have a button that stops a song.
    The music plays as soon as the file is open.
    What I am trying to do is upload 3 more songs and add a skip button that will skip to the next song.
    After the user clicks 4 times it goes back to the 1st songs again.
    I was going to avoid using a pause, a step back to previous song button and a volume slider.

    Here is the as code I have in it so far:

    stop();
    var sndTrack:SoundTrack = new SoundTrack();
    var sndControl:SoundChannel;
    sndControl = sndTrack.play(0,999);

    on_btn.addEventListener(MouseEvent.CLICK, soundOn);
    off_btn.addEventListener(MouseEvent.CLICK, soundOff);
    function soundOn(event:MouseEvent):void
    {
    sndControl = sndTrack.play(0,999);
    }
    function soundOff(event:MouseEvent):void
    {
    sndControl.stop();
    }

    If anyone could help that would be great!

  2. #2
    Member
    Join Date
    Feb 2007
    Location
    Sydney, Australia
    Posts
    44
    Well, first things first... uploading the new songs.
    Are you going to upload them all at once after your project starts or are you going to the next song in the series while the current one is playing or are you going to just upload each song every time the person presses the skip button?

    Or did you have something else in mind?

    What's the master plan?

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    4

    songs

    Im not really sure, what I have right now is when you open the interface the songs begins to play. I have a play and a stop button. What I want to do is have a foward button to when you click on it it goes to the next song, click it again than you go to the third song, click it again, than you are on the fourth song, and click it again, you are back on the 1st song. I guess like having four events that you skip through with a button but have it in action script and not in the button field.

  4. #4
    Member
    Join Date
    Feb 2007
    Location
    Sydney, Australia
    Posts
    44
    Well, since you seem to be focused mostly on the cycling aspect of the player, I guess we'll do that first.

    Scenario: You want to cycle through 4 clips in a forward only direction, right?

    So we're going through songs 1 to 4 sequentially, resetting back to one after passing 4.

    We'll need something to keep track of which song number we're currently on, so we'll need to store that in a persistent variable.

    Code:
    var songNum:int = 0;
    We'll put this at the top level of our code so it has the appropriate scope (variable can be accessed by everything and is persistent) and we'll start the numbering/index at 0 instead of 1, which is a good habit to get into when programming.

    Every time the skip button is pressed, we'll increment the songNum variable by one
    Code:
    ++songNum
    When after 4 clicks, the variable songNum will be equal to 4, and since we're working on a range from 0 to 3, 4 will be out of range and have to be reset back to the beginning, or 0. For this, we can use the handy modulus operator %, which returns the remainder after a division. This means
    Code:
    (4 % 4) == 0
    So we can write it as
    Code:
    songNum = (++songNum)%4
    So the code you should be adding, along with a button with the instance name of "next_btn", is
    Code:
    var songNum:int = 0;
    
    next_btn.addEventListener(MouseEvent.CLICK, soundNext);
    function soundNext(event:MouseEvent):void
    {
    songNum = (++songNum)%4;
    trace("Next song to be played is "+songNum);
    }
    Try pressing the next button several times... you'll see the output window trace 0, 1, 2, 3, 0, 1, 2, 3, 0, 1..... and so on.

    You can now use that songNum variable to identify the sound you want to play, however you want to do that.

    Got enough to go on?

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