music infinite loop?
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: music infinite loop?

  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
    FKs 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 11: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

  15. #15
    Member
    Join Date
    Oct 2001
    Posts
    50
    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);
    Can someone please tell me where to put this line of code in swish, i am totally newbie so please can you give me step by step instructions, I'll be grateful


    The sound will play for approximately 70 years!

  16. #16
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    If sound is external:
    PHP Code:
    var music:Sound = new Sound()
    music.load(new URLRequest("music.mp3")); 
    music.play(0int.MAX_VALUE); 
    // if music file is in another url (not in the same folder as the *.swf file) use "http://yoursite.com/music.mp3" instead.


    If sound is in library, with class name "music":
    PHP Code:
    var music1:music = new music();
    music1.play(0int.MAX_VALUE); 
    And i have a method to loop forever... you play it MAX_VALUE times, and add a listener to listen for the music to finishes, then play it it again MAX_VALUE times.

    PHP Code:
    var music1:music = new music();
    var 
    chan:SoundChannel = new SoundChannel();
    chan music1.play(0int.MAX_VALUE);
    chan.addEventListener(Event.SOUND_COMPLETEloop);
    function 
    loop(e:Event):void
    {
        
    chan music1.play(0int.MAX_VALUE);

    I have not waited for hours to see if it really loops, but I've waited quite long and it keeps playing...
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  17. #17
    Member
    Join Date
    Oct 2001
    Posts
    50
    Quote Originally Posted by angelhdz View Post
    If sound is external:
    PHP Code:
    var music:Sound = new Sound()
    music.load(new URLRequest("music.mp3")); 
    music.play(0int.MAX_VALUE); 
    // if music file is in another url (not in the same folder as the *.swf file) use "http://yoursite.com/music.mp3" instead.


    If sound is in library, with class name "music":
    [php]
    var music1:music = new music();
    music1.play(0, int.MAX_VALUE);
    ...
    Thanks a lot for trying to help me, I appreciate it.
    Can you please tell me where should I put the code? in which scene or frame? to be honest I never never used scripts in swish, so I totally lost
    Also, the sound is in Library, but, I don't understand what does the word 'class' refers to
    Note: um using swishmax 4
    Note: my file has so many scenes and I want it to play across all scenes
    Thanks again

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Sorry, the script is for flash as3. Swish doesn't support as3. Long time i don't use Swish so i can't help
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  19. #19

  20. #20
    Member
    Join Date
    Oct 2001
    Posts
    50
    Thanks a lot both of 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

Poll by Flashkit.com