-
[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
-
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.
-
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!
-
one question how do make an identifier for music? is it just its name?
-
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.
-
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|