-
AS2 sound frame and loop - trouble with next and back frame
hello.
in flash is not already created 4 years. I have problem.
For project are 4 frame:
1. main menu
2. Control / instructions
3. home game
4. board end game.
Problem:
In 1 frame attach sound with code AS2:
mySound=new Sound();
mySound.attachSound("sonar");
mySound.start();
stop(); // because menu with buttoms in first frame
In 3 frame stop sound:
mySound.stop("sonar");
to this point is ok. I go with 1 frame to 2 frame - ok, sound play - ok. But go 2 frame to 1 frame - sound play double in 1 frame.
Why? (after the passage of the second frame to the first sound should play again and not be double)
-
Prid - Outing
Hi,
the reason why this is happening is because the sound is already playing from frame 1 when you are on frame 2. When you go back to frame 1, a NEW sound object is created. Since the first sound is already playing, the new sound will also start playing. On frame 3, you actually stop the sound. You need to stop it on frame 1 as well, so add this to frame 1 actions:
Code:
mySound.stop(); // stop any playing sound
mySound=new Sound();
mySound.attachSound("sonar");
mySound.start();
stop(); // because menu with buttoms in first frame
Now, this is the simple solution, but your sound will re-start once you go back to frame 1 from frame 2. To prevent this, you will need to fix your code more, so I suggest you use the simple solution above
For a bit more advanced solution, use this code instead:
PHP Code:
onLoad = function(){ mySound=new Sound(); mySound.attachSound("sonar"); mySound.start(); stop(); // because menu with buttoms in first frame }
This will ensure that the sound played on Frame 1 will ONLY be played ONE TIME, and then never again. This will prevent the problem you are having with double sound playing, BUT, it may cause another problem. If you want to play the sound on Frame 1 again, after going to Frame 3 (which stops the sound), the sound will not play again. But I hope you don't want it to work like that, so hopefully this works as well.
I hope this helps
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
BIG THANKS. WORKS options 2.
But i dont this know. the important work. Thanks. ;]
or if I have a problem I could ask you a question?
(of course, in situations without output)
Last edited by dreq02; 01-22-2015 at 01:56 PM.
-
Prid - Outing
Hi,
I'm glad your problem is solved onLoad function ONLY plays the sound ONCE and then NEVER AGAIN -- when the flash is LOADING and has LOADED, then the sound will start, but after that, never again, that's why it works, in simple words, but it's okay if you don't know this as long as it works
Of course, if you have anymore questions, go ahead and ask, I would be glad to help you
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Originally Posted by Nig 13
Hi,
onLoad function ONLY plays the sound ONCE and then NEVER AGAIN -- when the flash is LOADING and has LOADED,
Of course, if you have anymore questions, go ahead and ask, I would be glad to help you
I think I understand. I have 2 or 3 problem in this weekend or days of the week. I will try to remove it yourself, but do not know if I can do it. For you, it's probably a simple thing
-
Prid - Outing
If you can't, just ask those questions here and we can help you
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
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
|