# Music player with volume slider

**URL:** <https://forum.kirupa.com/t/music-player-with-volume-slider/317135>\
**Category:** flash\
**Created:** [December 11, 2010, 1:34pm UTC](https://forum.kirupa.com/t/music-player-with-volume-slider/317135 "2010-12-11T13:34:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy4729](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Andy4729](https://forum.kirupa.com/u/Andy4729)\
**Post date:** [December 11, 2010, 1:34pm UTC](https://forum.kirupa.com/t/music-player-with-volume-slider/317135/1 "2010-12-11T13:34:33Z")

</div>

SO I’m trying to make a music player with play, pause and stop buttons aswell as a volume slider.

However, I’m getting these three errors:

Line 12 1046: Type was not found or was not a compile-time constant: Rectangle.  
Line 12 1180: Call to a possibly undefined method Rectangle.  
Line 12 1180: Call to a possibly undefined method Rectangle.

Here is my code:

```auto
package {
    import flash.events.*;
    import flash.display.*;
    import flash.media.*;
    import flash.net.URLRequest;

    public class music extends MovieClip {
        var musicPiece:Sound = new Sound(new URLRequest("piano01.mp3"));  
        var mySoundChannel:SoundChannel;  
        var isPlaying:Boolean = false;  
        var pos:Number = 0;  
       [COLOR=DarkRed] var rectangle:Rectangle = new Rectangle(0,0,100,0); [/COLOR]
        var dragging:Boolean = false;  
        
        public function music() {
            play_btn.addEventListener(MouseEvent.CLICK, play_);  
            pause_btn.addEventListener(MouseEvent.CLICK, pause_);
            stop_btn.addEventListener(MouseEvent.CLICK, stop_);
            volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);  
            stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);  
        }
            
        function play_(event:Event):void {  
            if (!isPlaying) {  
                mySoundChannel = musicPiece.play(pos);  
                isPlaying = true;  
            }  
        }  

        function pause_(event:Event):void {  
            if (isPlaying) {  
                pos = mySoundChannel.position;  
                mySoundChannel.stop();  
                isPlaying = false;  
            }  
        }  
   
        function stop_(event:Event):void {  
            if (mySoundChannel != null) {  
                mySoundChannel.stop();  
                pos = 0;  
                isPlaying = false;  
            }  
        } 

        function startDragging(event:Event):void {   
            volume_mc.mySlider_mc.startDrag(false,rectangle);  
            dragging = true; 
            volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);  
        } 

        function adjustVolume(event:Event):void {    
            var myVol:Number = volume_mc.mySlider_mc.x / 100;  
            var mySoundTransform:SoundTransform = new SoundTransform(myVol);  
            if (mySoundChannel != null) {  
                mySoundChannel.soundTransform = mySoundTransform;  
            }  
        }  
   
        function stopDragging(event:Event):void {  
            if (dragging) {  
                dragging = false;  
                volume_mc.mySlider_mc.stopDrag();  
            }  
        }
    }
}

```

The red line is the one that’s causing all three errors.

Any ideas anyone?

Thanks, Andy
