I have a sound SWF that plays fine on its own. But when I attach it to the main timeline of another SWF there’s no sound. How do I need to reference the Sound object and vars to get the Sound to play?
Here’s the code for the sound SWF:
var mainLoop:Sound = new Sound();
mainLoop.attachSound("mainPageLoop");
// Starts at beginning and loops 2 times.
mainLoop.start(0, 2);
mainLoopVolume = 100;
mainLoop.setVolume(mainLoopVolume);
mainLoop.onSoundComplete = function() { // Adding _root is necessary
_root.loadMovie("playSound.swf", this);
};
step = 1;
this.onEnterFrame = function() {
songDuration = _root.mainLoop.duration/1000;
songPosition = _root.mainLoop.position/1000;
//trace(songPosition);
//Note: the total duration is 13.719
// Each time position reaches 13.7 increment "step" var
if (songPosition>=13.7) {
step++;
//trace(step);
}
if (step>=2) {
fadeEnd = (songDuration-5); // Now use the current songDuration
if (fadeEnd<=songPosition && mainLoopVolume>0) {
if (mainLoopVolume<=1) {
mainLoopVolume = 0;
}
_root.mainLoop.setVolume(mainLoopVolume);
//mainLoopVolume = mainLoopVolume-1;
mainLoopVolume--;
}
}
};
Here’s a link to the test files: http://www.tornedgedesign.com/_test/attachSound.zip