So I have a scene which is an options menu; in the scene I have a volume slider; it works fine (I can slide it and the volume would go down/up), but when I leave the scene, it gives me an error (only happens if I play with the slider):
TypeError: Error #1009: Cannot access a property or method of a null object reference.
And it points at:
var myVolume:Number=V_Slider.V_Knob.x/mySliderLength;
and when I re-enter, the volume slider goes back to its original position. I'm very new to Flash and AS3, so any help I can get is very much appreciated.
Here is the code for the volume slider:
var dragging:Boolean=false;
var mySliderLength:uint=240;
var boundingBox:Rectangle=new Rectangle(0,0,mySliderLength,0);
V_Slider.V_Knob.addEventListener(MouseEvent.MOUSE_DOWN, dragKnob);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseKnob);
V_Slider.V_Knob.buttonMode=true;
function dragKnob(myEvent:Event):void {
V_Slider.V_Knob.startDrag(false, boundingBox);
dragging=true;
V_Slider.V_Knob.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function releaseKnob(myEvent:Event):void {
if (dragging) {
V_Slider.V_Knob.stopDrag();
dragging=false;
}
}
function adjustVolume(myEvent:Event):void {
var myVolume:Number=V_Slider.V_Knob.x/mySliderLength;
var myTransform:SoundTransform=new SoundTransform(myVolume);
if (BGM_SC!=null) {
BGM_SC.soundTransform=myTransform;
}
}