# Var musicChannel:SoundChannel;

**URL:** <https://forum.kirupa.com/t/var-musicchannel-soundchannel/298832>\
**Category:** Uncategorized\
**Created:** [October 26, 2009, 6:58am UTC](https://forum.kirupa.com/t/var-musicchannel-soundchannel/298832 "2009-10-26T06:58:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phingko](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@phingko](https://forum.kirupa.com/u/phingko)\
**Post date:** [October 26, 2009, 6:58am UTC](https://forum.kirupa.com/t/var-musicchannel-soundchannel/298832/1 "2009-10-26T06:58:35Z")

</div>

All happy people out there,  
need your help regarding my sound

So far I can load and play my sound in my main keyframe, the problem is when I want to make the sound off by clicking a checkbox\_mc to make it off,its not working  
I wonder if its caused by my structure

This is my code;

on the first keyframe  
var Music:Sound = new Sound();  
var musicChannel:SoundChannel;  
var url:String = “sound/intro.mp3”;  
var req:URLRequest = new URLRequest(url);  
Music.load(req);  
Music.play();

then when I clicked option button(same keyframe), I will unticked the checkbox(next keyframe) to make the music stop playing.

I used this code;

var isPlaying:Boolean = true;

function onCheck(evt:MouseEvent):void {  
switch (evt.target) {  
case mainOption\_mc.ok\_btn :  
gotoAndPlay(“menu”);  
break;  
case mainOption\_mc.checkboxMusic\_mc :  
if(isPlaying == true) {  
musicChannel.stop();  
mainOption\_mc.checkboxMusic\_mc.gotoAndPlay(“unticked”);  
isPlaying = false;  
}else {  
musicChannel= Music.play();  
mainOption\_mc.checkboxMusic\_mc.gotoAndPlay(“ticked”);  
isPlaying = true;  
}  
break;  
case mainOption\_mc.checkboxFullscr\_mc :  
gotoAndPlay(“unticked”);  
break;  
}  
}

Th eoutput I get now is that my musicChannel is a null object.  
So I put var musicChannel:SoundChannel; again inside the function  
however, it still said my musicChannel is null  
I don’t get it -.-  
I realized as I researched that SoundChannel in AS should be reannounced in every new keyframe since AS3 can’t keep it, no?

Can anyone give me a direction to fix this problem?

Thanks in advanced.
