# Sound SWF won't play when attached

**URL:** <https://forum.kirupa.com/t/sound-swf-wont-play-when-attached/209640>\
**Category:** flash\
**Created:** [December 11, 2006, 3:24am UTC](https://forum.kirupa.com/t/sound-swf-wont-play-when-attached/209640 "2006-12-11T03:24:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)\
**Post date:** [December 11, 2006, 3:24am UTC](https://forum.kirupa.com/t/sound-swf-wont-play-when-attached/209640/1 "2006-12-11T03:24:49Z")

</div>

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:

```auto

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](http://www.tornedgedesign.com/_test/attachSound.zip)
