# Action Script for volume control

**URL:** <https://forum.kirupa.com/t/action-script-for-volume-control/249049>\
**Category:** flash\
**Created:** [January 14, 2008, 10:04pm UTC](https://forum.kirupa.com/t/action-script-for-volume-control/249049 "2008-01-14T22:04:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibber4568](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jibber4568](https://forum.kirupa.com/u/jibber4568)\
**Post date:** [January 14, 2008, 10:04pm UTC](https://forum.kirupa.com/t/action-script-for-volume-control/249049/1 "2008-01-14T22:04:22Z")

</div>

Hi all.

Ok i have developed an XML mp3 player as part of an assignment i have due in tomorrow. I have everything working fine apart from the volume control.

We have only been taught how to do sound on and sound off. However i would really like to do a scrolling volume control. Bit like a cross fader which i have in place.

i managed to get some actionscript in order to do this but it confused me a little due to the use of \_parent refering to sound\_mc and sound\_obj. I am starting to understand more and believe that the way my whole player has been designed means i cant have this kind of volume control. Is this correct??

Here is the code for my entire player, the volume control code is towards the bottom but obviously doesnt work. The vertFader, fade\_bg and fader\_btn are each variables that i currently have on stage.

Any help is very much appreicated.

```auto

var mp3:XML = new XML();
mp3.ignoreWhite = true;
var songArray:Array = new Array();
var urls:Array = new Array();
var titles:Array = new Array();
var currentIndex:Number = 0;

var player:Sound = new Sound();

mp3.onLoad = function(success){
    
    if (success) 
    {
        songArray = mp3.firstChild.childNodes;
        for(i=0;i<songArray.length;i++) {
            urls.push(songArray*.attributes.url);
            titles.push(songArray*.attributes.title);
            
        }
        player.loadSound(urls[currentIndex],true);
        title_txt.text = titles[currentIndex];
        
    }
    else 
    {
        title_txt.text = "The MP3 player is currently out of order. Please try again later.";
    }
}

mp3.load("mp3s1.xml");

//-----CONTROLS------//

var currentPosition:Number = 0;
var paused:Boolean = false;

stop_btn.onRelease = function(){
    
    currentPosition = 0;
    player.stop();
    paused = true;
}

play_btn.onRelease = function(){
    
    if(paused){
    player.start(currentPosition);
    paused = false;
    
    }
}

pause_btn.onRelease = function(){
    
    if(!paused){
    currentPosition = player.position/1000;
    player.stop();
    paused = true;
    
    }
    else
    {
        if(currentPosition > 0){
        player.start(currentPosition);
        paused = false;
        }
    }
}

//-----Next & previous buttons-----//

function nextSong(){
    
    if(songArray[currentIndex +1]){
        
        currentIndex++;
    }
    else{
        
        currentIndex = 0;
    }
    player.loadSound(urls[currentIndex],true);
    title_txt.text = titles[currentIndex];
    
    
}

function prevSong(){
    
    if(currentIndex > 0){
        
        currentIndex --;
    }
    else
    {
        currentIndex = songArray.length -1;
    }
    player.loadSound(urls[currentIndex],true);
    title_txt.text = titles[currentIndex];
    
}

next_btn.onRelease = nextSong;

bck_btn.onRelease = prevSong;

//------Volume Control------//

this._parent.fader_btn.vertFader.onPress = function(){
startDrag(this,
true,0,this._y,this._parent.fade_bg._width,this._y);
}

this.onEnterFrame = function () {
var g = (this._x/this._parent.fade_bg._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume(g);
}
this._parent.fader_btn.vertFader.onRelease = function(){
    delete this.onEnterFrame
stopDrag();

}
this._parent.fader_btn.vertFader.onReleaseOutside = function() {
stopDrag();
}

//---------Scrolling Text-------------//

this.onEnterFrame = function() {
    if (title_txt.hscroll<title_txt.maxhscroll) {
        title_txt.hscroll += 2;
    } else if (title_txt.hscroll == title_txt.maxhscroll) {
        title_txt.hscroll = 1;
    }
};
stop();

```
