# Volume slider within movieclip not working - need help

**URL:** https://forum.kirupa.com/t/volume-slider-within-movieclip-not-working-need-help/190104
**Category:** Uncategorized
**Created:** [June 8, 2006, 5:31pm UTC](https://forum.kirupa.com/t/volume-slider-within-movieclip-not-working-need-help/190104 "2006-06-08T17:31:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![danwangkw](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@danwangkw](https://forum.kirupa.com/u/danwangkw)
#### Post date: [June 8, 2006, 5:31pm UTC](https://forum.kirupa.com/t/volume-slider-within-movieclip-not-working-need-help/190104/1 "2006-06-08T17:31:09Z")

</div>

Need help from the good folks here. Post is rather long, please bear with me.

I have a volume slider which controls a sound object within an empty movieclip (placed outside the canvas area)

In my main timeline, I have the following code:

```auto

[COLOR=red]_root.[/COLOR]myMusic=new Sound( **myMusic_mc** ); 
_root.myMusic.attachSound(" **bgmusic01**");
_root.myMusic.start(0,999);
_root.myMusicVolume=50;
_root.myMusic.setVolume(myMusicVolume);

```

**myMusic\_mc** is the instance name of the empty movie clip.

**bgmusic01** is the linkage identifier for my .wav file which I exported for actionscript.

My slider (the one to drag) movieclip instance name is **hslider**.  
My slider ‘track’ movieclip instance name is **hbase**.

Actionscript (adapted from [kennybellew.com](http://kennybellew.com)) is given for the movieclip **hslider** :

```auto

onClipEvent(load) {
    this._x=_root.hbase._x + _root.hbase._width/2 - this._width/2;
    left=this._x - _root.hbase._width/2;
    top=this._y; 
    right=this._x + _root.hbase._width/2;
    bottom=this._y; 
    volCalc=_root.hslider._x - _root.hbase._width/2
//
//End of Clip Event Load
}
onClipEvent(enterFrame) {
this.onPress = function () {
    startDrag(this, false, left , top , right, bottom)
}
this.onRelease = function () {
    this.stopDrag();
}
// This constantly sets the current a-axis position of
//the slider to "sliderx
    sliderx=_root.hslider._x; //Sets sliderx as variable for a-axis of slider
    myMusicVolume=(sliderx-volCalc); //The value of x-axis load value - n = 50
    _root.myMusic.setVolume(myMusicVolume);
    _root.currentVolume="Volume " + _root.myMusic.getVolume();
}

```

Volume is set to 50% at the start. Everything above works fine.

However, I have in mind a button to toggle the visibility of this volume slider so I plonked the whole lot (i.e. copy frames for all the volume slider elements) into a new movieclip. When I drag this movieclip onto the canvas and publish the swf, the volume slider doesn’t work anymore:

a) there is no sound  
b) when I clicked on the slider to drag it, it snaps to the left of the slider track

I figured the reason why it had no sound has something to do with ‘[COLOR=red]\_root[/COLOR][COLOR=black]’[/COLOR].

But as to why the slider doesn’t behave the way it should, it’s beyond me.

The attached swf shows the problem with the slider ‘snapping’ to the left. Download the .fla from my website to get a better picture:

\>\> [**[COLOR=seagreen]bgmusic\_controller3.fla[/COLOR]**](http://www.sgdanielwang.com/flash/bgmusic_controller3.fla) (1.7mb, includes the imported loop .wav)

Any assistance would be greatly appreciated.

Rgds,  
Dan
