A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Junior Member
    Join Date
    Jun 2000
    Posts
    9

    Cool

    how i can do a music infinite loop for background music?

  2. #2
    just set the loop to 9999 i think that should do the trick,
    i dont think theres an option for an infinite loop

    oioi

  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    you can also put the music in a movie clip

  4. #4
    Senior Moderator ®
    FK´s Banning Machine ™
    GMF ™'s Avatar
    Join Date
    Feb 2000
    Location
    Oslo, Norway
    Posts
    5,697
    it is 999

  5. #5
    Junior Member
    Join Date
    Jun 2000
    Posts
    9

    where?? & movie clip?

    where i put the 9999??
    in properties? sound? actions? or where? :P

    and.. for the movie clip
    how i do make the sound loop using a movie clip?

  6. #6
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    click on Insert >>>

    New Symbol >>> Behavior: movie clip

    next add the music to keyframe1
    in the movie clip
    set the Sync to event
    set the loop to 99 times

    If you don't know how to set the loop and sync
    then i suggest you read the help files.

  7. #7
    Junior Member
    Join Date
    Jan 2007
    Posts
    4
    Sorry to resurrect an old thread, but this is the one that came up in my google search, so I thought it'd be good to post a solution so anyone else who's trying to find the answer will have it.

    Anyway, I came across this quick little trick that easily sets up an infinite loop without using any sort of 999 repeats (which can be problematic in long games or short loops, and just seems dangerous in general):

    music1.start();
    music1.onSoundComplete = function() {this.start();}

  8. #8
    Moderator
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    note that onSoundComplete does not guarantee a seemless loop.

    I believe that starting with Flash 8 you could specifiy "infinite" loop in sound properties for sounds on the timeline, though this does not help the problem with infinite loop in sound object.
    aviarts.com - web development and flash development

  9. #9
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    i just tried this and it seems to work. it uses the sound object
    PHP Code:
    song = new Sound();
    song.loadSound("your.mp3"true);
    onEnterFrame = function () {
        
    pos song.position/1000;
        
    dur song.duration/1000;
        if (
    pos>=dur) {
            
    song.start();
        }
    }; 
    Last edited by EQFlash; 04-16-2008 at 10:40 AM.
    If you don't think you're going to like the answer, then don't ask the question.

  10. #10
    Junior Member
    Join Date
    May 2008
    Location
    Fort White, FL
    Posts
    1

    Flex 3.0 in AS3

    I just started flex a few days ago. I looked all over for a way how to loop background music. The only idea that I found worked was to put in the rediculously large # into the loop argument. Like so :

    MySound.play(0, 999);

    But I looked to the help files after still not satisfied~ In there I found SoundChannel. Used as so:

    var channel : SoundChannel = MySound.play(0, 0);

    You can catch the event when the song ends like so:

    channel.addEventListener(Event.SOUND_COMPLETE, PlayAgain);

    And here is how I handled that event:

    private function PlayAgain(event : Event) : void
    {
    channel.stop(); //<---- this I added just in case
    channel.removeEventListener(Event.SOUND_COMPLETE, PlayAgain);
    channel = MySound.play(0, 0);
    channel.addEventListener(Event.SOUND_COMPLETE, PlayAgain);
    }


    I had to declare the sound and the channel as members of the class for this to work due to scope and the inability to assign anything to the event.target. For some reason the sound will not loop if you just set the channel equal to the sound. It will play a second time but thats it! So I added another event listener to try an make it play again. Now I wasn't sure if the event listeners, if already set, stack in AS3. So as to not have thousands of the same event listener on this one channel I remove it just before reassigning the sound to the channel. I looped sounds past 6 times so i'm going to say this works well. I hope this helps.

  11. #11
    Junior Member
    Join Date
    Dec 2008
    Posts
    1
    I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
    Code:
    this.play(0, int.MAX_VALUE);
    The sound will play for approximately 70 years!

  12. #12
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    man that stinks so what i did was i made it start inside a movieclip and in the movieclip is 2 frames first one makes it start second stops it and when you press quit make it go to nextFrame(); for movieclip before it goes to another frame

  13. #13
    Registered User
    Join Date
    Aug 2012
    Posts
    1
    Quote Originally Posted by ookpalm View Post
    I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
    Code:
    this.play(0, int.MAX_VALUE);
    The sound will play for approximately 70 years!

    thank you so much man, this code was EXACTLY what i was looking for! quick simple and easy way to loop some BG music or anything of the like, thanks again!

  14. #14
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    I tried this, it worked. Thank you

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