Hello! So, here's my situation: I'm working on a flash project in which a song is playing in a menu. You can click a button to go to the next frame, frame 2. If you press a button on frame 2, it brings you back to frame 1. At that point, the song will start playing again, causing multiple instances of the song to start playing. I'd like to find out how I can go about having the song just play and loop normally, unaffected by the user returning to the first frame. One other thing I should mention is that I'm doing it this way rather than just having the sound play on another layer on the timeline because I need the sound channel set up for a later section in which a movie clip plays a short animation with sound, and the music must be turned off at that point. Plus, plain and simple, it's nice to learn a little more about AS3 and have nice, clean solutions to these things rather than half-assing frames and layers around. Here's my code so far, along with notes on what my logic was for each step:
var mySound:music = new music();
var myChannel:SoundChannel = new SoundChannel();
// Setting the sound and channel up.
if (myChannel.position > 0) {
var isPlaying:Boolean = true;
}
// Setting up a variable to determine if if a channel's playing.
if (!isPlaying) {
mySound.play();
trace("starting up");
}
// If it's not already playing, then do it!
if (isPlaying) {
myChannel.stop();
trace("turnoff");
isPlaying = false;
}
//When the frame is entered a second time, a second instance of mySound will start playing. The purpose of this section is to stop that instance. So far, it's been unaffective; I'm still only getting "starting up" in the output each time I return to the frame.
In a nutshell, I'm thinking that this might be a logic issue that I'm having, or maybe I'm going about this whole thing the wrong way...I found a bunch of other people having this issue on Google, but none of those solutions worked the way I needed them to. Thanks a ton to anyone who can help!