A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [MX04]how do you repeat music with actionscript

  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    80

    [MX04]how do you repeat music with actionscript

    the title pretty much explains it i just want to play a sond called "Glide Long.aif" in my game and i want it to repeat automaticlly at the end of the song i dont know if this is realevent but it lasts 465 frames hehe cool smileys

  2. #2
    come 'ere a minute
    Join Date
    May 2004
    Location
    BC, Canada
    Posts
    50
    Quite a few ways I would think.

    1. If it's loaded directly into your timeline, put a gotoAndPlay(1); action on the end frame.

    2. If it's loaded externally, I think the audio object has a way to get the current playing time and the total time of the clip. Then write a condition statement saying if(current == total){ //do this }

    3. You could write a timer, that is set to trigger at the exact time your audio clip ends, which triggers a gotoAndPlay(1); action.
    http://www.streamsearch.ca - The music you want, when you want it
    http://www.machonemedia.ca - Web development and other media related services
    http://www.myshortfilms.com - A community for short film makers to comment and rate films

  3. #3
    Member
    Join Date
    Jun 2007
    Posts
    40
    I just had to do this in my Mars Defense game. There are two ways to do it, both very easy, I'm assuming you've imported the sound file of the song into your library.

    The first way is like this:
    code:

    var my_music:Sound = new Sound();
    my_music.attachSound("music"); //in place of 'music' put whatever the identifier is for the music file
    my_music.start(0,99);// The first number is the offset in seconds from the beginning of the song, I assume you want to start at the beginning, the second number is the number of times you want it to loop.



    That will repeat the song 99 times or until your movieclip ends, whichever comes first. If you dont know how long your movie will play you can have it loop infinitely like this.

    code:

    var my_music:Sound = new Sound();
    my_music.attachSound("music");
    my_music.onSoundComplete = function()
    {
    my_music.start();
    }
    my_music.start(); //Make sure to include this line so it starts the first time


    Every time the song completes it triggers the completion function and starts the song again.

    Hope that helped!

  4. #4
    Banned
    Join Date
    Mar 2007
    Posts
    80
    one question how do make an identifier for music? is it just its name?

  5. #5
    Member
    Join Date
    Jun 2007
    Posts
    40
    if you right click on the sound in your library and click on linkage you'll see a field called identifier. Type in the name you want to use there.
    Check out my game: Mars Defense ! Message me with any comments, suggestions or bugs.

  6. #6
    Banned
    Join Date
    Mar 2007
    Posts
    80
    k thanks

  7. #7
    Banned
    Join Date
    Mar 2007
    Posts
    80
    it works now thanks

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