A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: how to tell an attached and looped sound not to re-play from the begining?

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    how to tell an attached and looped sound not to re-play from the begining?

    hello ^^

    ok, i read the FAQ, took a look at the movie section, but didn't find what i'm looking for...
    i'm currently doing a small game, and i have a backgroud music that loops; it's an attached sound in fact.

    what i want to do with it:
    the original sound file is composed with the intro music, and the part that is supposed to loop. i don't want the loop to repeat the entire music, just to play it from the begining (so with the intro) the first time it's played, then loop let's say at the middle of the track... is it possible to do it? or is it better to cut the original sound file and work that way?

    thanks for your help ^^

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    ----
    i don't want the loop to repeat the entire music, just to play it from the begining (so with the intro) the first time it's played, then loop let's say at the middle of the track
    ----
    you can do this one of two ways. if you need backward compatibility with Flash 5 your best bet is to use the loop mix sequencing technique described in the FAQ. This requires timeline sounds (but you can control timeline sounds with a sound object if that is a concern).

    if your audience is Flash MX only, then you have another option.

    1) figure out the loop starting point in fractions of a second. In other words, figure out the millisecond postion for the end of the intro and divide by 1000 to convert to seconds. This will be the loop point.

    2) use onSoundComplete() to call the start method and loop the portion of the sound you need.

    Code:
    /*
    Flash MX only
    onsoundcomplete restarts the sound 
    looping at the new starting position
    */
    introEndPos = 1250/1000; // start 1.25 seconds into the sound
    mysound.onSoundComplete = function () {mysound.start(introEndPos,9999)}
    mysound.start(); // play the entire sound once
    Last edited by hp3; 11-17-2002 at 04:39 PM.

  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks a lot, hp3, i'll give it a try.

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