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:
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