We help IT Professionals succeed at work.
Get Started

How do I control the Volume of the alarm tune live ???

akulavi
akulavi asked
on
367 Views
Last Modified: 2013-11-11
In my Flex Project i need to create a stopwatch with an alarm. For that I had included 5 types of Alarm Tune and it can ring upto 10,20 and 30 times at a specified time interval. Therefore, I have made 15 different tunes. Now I had also make one volume control using Slider control. Everytime the type of alarm rings it will check the vol. level through one hidden field. This hidden field will contain the slider value. According to that value the volume is set. For 5 x 3 types of alarm I had declared 15 separate methods. With the help of SoundTransform class I had mentioned the vol. level. If the alarm once starts ringing, then I have no control to increase / decrease the volume level or I cannot mute it. I am giving you my code below. I am giving you the .mxml and the .css file. Please go through it and tell me by how can I have one single instance of Alarm which is accessible in anywhere so that I can mute that particular object or increase / decrease the vol. of that object at that very moment when user want it. In my case as I have used the hidden field to store those values, I am unable to implement those functionality. My code will increase / decrease the volume in the next instance i.e. next time when the alarm rings ............

.mxml code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      layout="absolute"
      backgroundGradientAlphas="[1.0, 1.0]"
      backgroundGradientColors="[#000000, #494848]"
      width="780"
      height="202"
      xmlns:net="flash.net.*" creationComplete="init()"
      xmlns:media="flash.media.*" xmlns:controls="kb.controls.*" xmlns:local="*">
      <mx:Style source="style.css"/>
      <mx:Spacer height="70"/>
      <mx:Label id="hlab" visible="false"/>
      <mx:Label id="beep" visible="false" text="10"/>
      <mx:Label id="snd" visible="false" text="1"/>
      <mx:Label id="pause" visible="false" text="0"/>
      <mx:Label id="loop" visible="false" text="0"/>
      <mx:Label id="alarm" visible="false" text="1"/>
            
      
      <mx:HBox width="100%" horizontalAlign="center" height="73" verticalAlign="middle" y="25">
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb1" styleName="VboxSelect">
                  <mx:Label id="l1" text="Stage 1" color="#FBFAFA"/>
                  <mx:TextInput x="10" y="10" width="51" id="txt1" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="8" textAlign="center"/>
                  <mx:Label id="l1b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb2" >
                  <mx:Label id="l2" text="Stage 2" color="#FBFAFA"/>
                  <mx:TextInput x="69" y="10" width="51" id="txt2" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="3" textAlign="center"/>
                  <mx:Label id="l2b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb3" >
                  <mx:Label id="l3" text="Stage 3" color="#FBFAFA"/>
                  <mx:TextInput x="128" y="10" width="51" id="txt3" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="6" textAlign="center">
                        
                  </mx:TextInput>
                  <mx:Label id="l3b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb4" >
                  <mx:Label id="l4" text="Stage 4" color="#FBFAFA"/>
                  <mx:TextInput x="187" y="10" width="51" id="txt4" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="9" textAlign="center"/>
                  <mx:Label id="l4b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb5" >
                  <mx:Label id="l5" text="Stage 5" color="#FBFAFA"/>
                  <mx:TextInput x="246" y="10" width="51" id="txt5" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="14" textAlign="center"/>
                  <mx:Label id="l5b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb6" >
                  <mx:Label id="l6" text="Stage 6" color="#FBFAFA"/>
                  <mx:TextInput x="305" y="10" width="51" id="txt6" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="16" textAlign="center"/>
                  <mx:Label id="l6b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb7" >
                  <mx:Label id="l7" text="Stage 7" color="#FBFAFA"/>
                  <mx:TextInput x="364" y="10" width="51" id="txt7" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="16" textAlign="center"/>
                  <mx:Label id="l7b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:VBox width="59" borderColor="#000000"  horizontalAlign="center" id="vb8" >
                  <mx:Label id="l8" text="Stage 8" color="#FBFAFA"/>
                  <mx:TextInput x="423" y="10" width="51" id="txt8" maxChars="3" displayAsPassword="false" editable="true" enabled="true" text="3" textAlign="center"/>
                  <mx:Label id="l8b" text="Min" color="#FBFAFA"/>
            </mx:VBox>
            <mx:Label text="00:00:00" fontSize="24" color="#FDFEFE" fontFamily="Arial" id="swLabel"/>
            <mx:Image buttonMode="true" useHandCursor="true" source="play.png" height="32" width="36" click="playClick()" toolTip="Start the Timer"/>
            <mx:Image buttonMode="true" useHandCursor="true" source="stop.png" width="30" height="26" click="stopClick()" toolTip="Stop the Timer"/>
      </mx:HBox>
      <!-- <mx:HBox width="492" height="17" x="61" y="106" horizontalAlign="center">
            <mx:HSlider id="hslide" minimum="1" maximum="8" width="492"  height="0" sliderThumbClass="BigThumbClass" />
      </mx:HBox> -->
      <mx:HBox width="300" height="28" verticalAlign="middle" x="40" y="100">
            <mx:Label id="t2" text="Preset Timers" color="#FEFEFE"/>
            <mx:Button label="T1" id="pre1" click="preset1()" toolTip="Set the time according to the selected Preset"/>
            <mx:Button label="T2" id="pre2" click="preset2()" toolTip="Set the time according to the selected Preset"/>
            <mx:Button label="T3" id="pre3" click="preset3()" toolTip="Set the time according to the selected Preset"/>
            <mx:Button label="T4" id="pre4" click="preset4()" toolTip="Set the time according to the selected Preset"/>
      </mx:HBox>
      <mx:HBox width="731" height="28" verticalAlign="middle" x="40" y="132">
            <mx:Label id="t3" text="Alarm Tune " color="#FEFEFE"/>
            <mx:Button label="A1" id="al1" click="alarmtune1()" toolTip="Alarm 1"/>
            <mx:Button label="A2" id="al2" click="alarmtune2()" toolTip="Alarm 2"/>
            <mx:Button label="A3" id="al3" click="alarmtune3()" toolTip="Alarm 3"/>
            <mx:Button label="A3" id="al4" click="alarmtune4()" toolTip="Alarm 4"/>
            <mx:Button label="A5" id="al5" click="alarmtune5()" toolTip="Alarm 5"/>
            <mx:Spacer width="30"/>
            <mx:Label id="t1" text="Times To Beep" color="#FEFEFE"/>
            <mx:Button label="10" id="b1" click="beep1()" toolTip="Repeat the beep 10 times"/>
            <mx:Button label="20" id="b2" click="beep2()" toolTip="Repeat the beep 20 times"/>
            <mx:Button label="30" id="b3" click="beep3()" toolTip="Repeat the beep 30 times"/>
            <mx:Image buttonMode="true" useHandCursor="true" source="sound.png" width="30" height="26" click="muteClick()" id="soundimg"/>
            <mx:CheckBox label="Repeat" id="chk1" selected="false" enabled="true" click="loopClick()" fillColors="[red,haloOrange,yellow,haloGreen]"
            themeColor="black" width="68" fontSize="11" fillAlphas="1"/>
      </mx:HBox>
      <net:URLRequest id="alm1" url="alarm1.mp3" />
      <net:URLRequest id="alm2" url="alarm2.mp3" />
      <net:URLRequest id="alm3" url="alarm3.mp3" />
      <media:SoundChannel id="mySoundChannel" />
      <media:Sound id="mySound" />
      <mx:Number id="myPos">0</mx:Number>
      <mx:Script>
            <![CDATA[
                  import com.flexandair.StopWatch;
                  import mx.core.SoundAsset;
            import flash.media.*;
            import mx.controls.*;
                  [Bindable] private var stopWatch:StopWatch = new StopWatch();
                  [Bindable] private var isRunning:Boolean = false;
                  [Embed(source="alarm1.mp3")]
                  
                  [Bindable]
            public var Song:Class;
            public var mySong:SoundAsset = new Song() as SoundAsset;
            public var channel:SoundChannel;
           
            // HIDDEN FIELD DETAILS
            // hlab = it is for keeping track of the intervals
            // beep = it is used for selecting which mp3
            // snd = it is used for whether sound will on or it will mute . "1" = "Sound On"|| "0" = "Mute"
            // pause = it is used to check whether the Pause button had been pressed or not . "1" = "Paused Clicked" || "0" = "Paused Not Clicked"
            // loop = it is used to activate / deactivate loop button. Default loopoff. "1" = "Loop On" || "0" = "Loop Off"
            // alarm = it is used to select the alarm tune as per user's choice... A1="1" || A2="2" || A3="3" || A4="4 || A5="5"
           
           
           
            private function init():void
            {
                  txt1.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt2.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt3.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt4.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt5.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt6.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt7.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
                  txt8.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
            }
            private function reportKeyDown(e:KeyboardEvent):void
            {
                  var numstr:String = String.fromCharCode(e.charCode);
                  if (numstr == "1" || numstr == "2" || numstr == "3" || numstr == "4" || numstr == "5" || numstr == "6" || numstr == "7" || numstr == "8" || numstr == "9" || numstr == "0" || e.charCode == 9 || e.charCode == 8 || e.charCode == 127)
                  {
                        if (numstr == "1" || numstr == "2" || numstr == "3" || numstr == "4" || numstr == "5" || numstr == "6" || numstr == "7" || numstr == "8" || numstr == "9" || numstr == "0")
                        {
                              var num:int = parseInt(numstr);
                              if (num <1 || num > 999)
                              {
                                    Alert.show("Number should be between 1 - 999");
                                    return;
                              }
                        }
                  }
                  else
                  {
                        Alert.show("Number should be between 1 - 999 !!!" );
                        return;
                  }
            }
            private function playEmbeddedSounda10():void{
                   var soundCSSClassDec:CSSStyleDeclaration
                      = StyleManager.getStyleDeclaration("MySounda10");
                   var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                   var myEmbeddedSound:Sound = new MySoundClass() as Sound;
                   var trans:SoundTransform = new SoundTransform(vol.value);                  
                       myEmbeddedSound.play(0,0,trans);            
                               
                   }
                   private function playEmbeddedSounda20():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySounda20");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
                   private function playEmbeddedSounda30():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySounda30");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }      
                   private function playEmbeddedSoundb10():void{
                   var soundCSSClassDec:CSSStyleDeclaration
                      = StyleManager.getStyleDeclaration("MySoundb10");
                   var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                   var myEmbeddedSound:Sound = new MySoundClass() as Sound;
                   var trans:SoundTransform = new SoundTransform(vol.value);                  
                       myEmbeddedSound.play(0,0,trans);            
                               
                   }
                   private function playEmbeddedSoundb20():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundb20");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
                   private function playEmbeddedSoundb30():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundb30");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }      
                   private function playEmbeddedSoundc10():void{
                   var soundCSSClassDec:CSSStyleDeclaration
                      = StyleManager.getStyleDeclaration("MySoundc10");
                   var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                   var myEmbeddedSound:Sound = new MySoundClass() as Sound;
                   var trans:SoundTransform = new SoundTransform(vol.value);                  
                       myEmbeddedSound.play(0,0,trans);            
                               
                   }
                   private function playEmbeddedSoundc20():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundc20");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
                   private function playEmbeddedSoundc30():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundc30");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }      
                   private function playEmbeddedSoundd10():void{
                   var soundCSSClassDec:CSSStyleDeclaration
                      = StyleManager.getStyleDeclaration("MySoundd10");
                   var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                   var myEmbeddedSound:Sound = new MySoundClass() as Sound;
                   var trans:SoundTransform = new SoundTransform(vol.value);                  
                       myEmbeddedSound.play(0,0,trans);            
                               
                   }
                   private function playEmbeddedSoundd20():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundd20");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
                   private function playEmbeddedSoundd30():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySoundd30");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }      
                   private function playEmbeddedSounde10():void{
                   var soundCSSClassDec:CSSStyleDeclaration
                      = StyleManager.getStyleDeclaration("MySounde10");
                   var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                   var myEmbeddedSound:Sound = new MySoundClass() as Sound;
                   var trans:SoundTransform = new SoundTransform(vol.value);                  
                       myEmbeddedSound.play(0,0,trans);            
                               
                   }
                   private function playEmbeddedSounde20():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySounde20");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
                   private function playEmbeddedSounde30():void{
                         var soundCSSClassDec:CSSStyleDeclaration
                            = StyleManager.getStyleDeclaration("MySounde30");
                         var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
                         var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
                         var trans:SoundTransform = new SoundTransform(vol.value);            
                             myEmbeddedSound.play(0,0,trans);            
                                     
                   }
            public function playSound():void
            {
                        //*************** EMBED LOGIC ***************
                // Make sure we don't get multiple songs playing at the same time
                //stopSound();
               
                // Play the song on the channel
                //channel = mySong.play();
                //************** EMBED LOGIC *****************
                if (snd.text == "1")
                {
                      var beeptext:String = beep.text;
                      var alarmtext:String = alarm.text;
                      if (beeptext == "10" && alarmtext == "1")
                      {
                            playEmbeddedSounda10();
                      }
                      else if (beeptext == "20" && alarmtext == "1")
                      {
                            playEmbeddedSounda20();
                      }
                      else if (beeptext == "30" && alarmtext == "1")
                      {
                            playEmbeddedSounda30();
                      }
                      if (beeptext == "10" && alarmtext == "2")
                      {
                            playEmbeddedSoundb10();
                      }
                      else if (beeptext == "20" && alarmtext == "2")
                      {
                            playEmbeddedSoundb20();
                      }
                      else if (beeptext == "30" && alarmtext == "2")
                      {
                            playEmbeddedSoundb30();
                      }
                      if (beeptext == "10" && alarmtext == "3")
                      {
                            playEmbeddedSoundc10();
                      }
                      else if (beeptext == "20" && alarmtext == "3")
                      {
                            playEmbeddedSoundc20();
                      }
                      else if (beeptext == "30" && alarmtext == "3")
                      {
                            playEmbeddedSoundc30();
                      }
                      if (beeptext == "10" && alarmtext == "4")
                      {
                            playEmbeddedSoundd10();
                      }
                      else if (beeptext == "20" && alarmtext == "4")
                      {
                            playEmbeddedSoundd20();
                      }
                      else if (beeptext == "30" && alarmtext == "4")
                      {
                            playEmbeddedSoundd30();
                      }
                      if (beeptext == "10" && alarmtext == "5")
                      {
                            playEmbeddedSounde10();
                      }
                      else if (beeptext == "20" && alarmtext == "5")
                      {
                            playEmbeddedSounde20();
                      }
                      else if (beeptext == "30" && alarmtext == "5")
                      {
                            playEmbeddedSounde30();
                      }
                }
            }
             public function stopSound():void
            {

                // Stop the channel, but only if it exists
                if ( channel != null )channel.stop();
               //if (mySoundChannel != null) mySoundChannel.stop();
            }
            private function alarmtune1(): void
            {
                  alarm.text="1";
                  al1.alpha=0.3;
                  al2.alpha=1;
                  al3.alpha=1;
                  al4.alpha=1;
                  al5.alpha=1;
            }
            private function alarmtune2(): void
            {
                  alarm.text="2";
                  al1.alpha=1;
                  al2.alpha=0.3;
                  al3.alpha=1;
                  al4.alpha=1;
                  al5.alpha=1;
            }
            private function alarmtune3(): void
            {
                  alarm.text="3";
                  al1.alpha=1;
                  al2.alpha=1;
                  al3.alpha=0.3;
                  al4.alpha=1;
                  al5.alpha=1;
            }
            private function alarmtune4(): void
            {
                  alarm.text="4";
                  al1.alpha=1;
                  al2.alpha=1;
                  al3.alpha=1;
                  al4.alpha=0.3;
                  al5.alpha=1;
            }
            private function alarmtune5(): void
            {
                  alarm.text="5";
                  al1.alpha=1;
                  al2.alpha=1;
                  al3.alpha=1;
                  al4.alpha=1;
                  al5.alpha=0.3;
            }
            private function preset1() :void
            {
                  txt1.text="8";
                  txt2.text="3";
                  txt3.text="6";
                  txt4.text="9";
                  txt5.text="14";
                  txt6.text="16";
                  txt7.text="16";
                  txt8.text="3";
                  pre1.alpha = .3;
                  pre2.alpha = 1;
                  pre3.alpha = 1;
                  pre4.alpha = 1;
            }
            private function preset2() :void
            {
                  txt1.text="9";
                  txt2.text="5";
                  txt3.text="9";
                  txt4.text="13";
                  txt5.text="17";
                  txt6.text="20";
                  txt7.text="20";
                  txt8.text="5";
                  pre1.alpha = 1;
                  pre2.alpha = .3;
                  pre3.alpha = 1;
                  pre4.alpha = 1;
            }
            private function preset3() :void
            {
                  txt1.text="10";
                  txt2.text="7";
                  txt3.text="12";
                  txt4.text="17";
                  txt5.text="20";
                  txt6.text="24";
                  txt7.text="24";
                  txt8.text="7";
                  pre1.alpha = 1;
                  pre2.alpha = 1;
                  pre3.alpha = .3;
                  pre4.alpha = 1;
            }
            private function preset4() :void
            {
                  txt1.text="11";
                  txt2.text="9";
                  txt3.text="15";
                  txt4.text="21";
                  txt5.text="23";
                  txt6.text="28";
                  txt7.text="28";
                  txt8.text="9";
                  pre1.alpha = 1;
                  pre2.alpha = 1;
                  pre3.alpha = 1;
                  pre4.alpha = .3;
            }
            private function beep1() :void
            {
                  beep.text = "10";
                  b1.alpha = 0.3;
                  b2.alpha = 1;
                  b3.alpha = 1;
            }
            private function beep2() :void
            {
                  beep.text = "20";
                  b1.alpha = 1;
                  b2.alpha = 0.3;
                  b3.alpha = 1;
            }
            private function beep3() :void
            {
                  beep.text = "30";
                  b1.alpha = 1;
                  b2.alpha = 1;
                  b3.alpha = 0.3;
            }
           
                  private function pauseTime():void
                  {
                        pause.text="1";
                        stopWatch.pause();
                  }
                  private function updateTime(e:Event):void {
                        if (pause.text == "1")
                        {
                              swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                              stopWatch.pause();
                              isRunning = false;
                        }
                        else
                        {
                              var time:String = stopWatch.getTimeStampAsString();
                              swLabel.text = time;
                              
                              var pos:int = time.lastIndexOf(":");
                              var pos1:int = time.indexOf(":");
                              var ch:String = time.substring(pos1+1,pos); // for Minutes
                              //var ch:String = time.substring(pos+1); // for Seconds
                              var chint:int = parseInt(ch);
                              //pre1.label=ch;
                              if (hlab.text == "1" && chint == parseInt(txt1.text))
                              {
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          stopWatch.reset();
                                          playSound();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text = "2";
                                          ////hslide.value = 2;
                                          //VBoxColor(2);
                                          VBoxColor(2);
                                          if (txt2.text == "0")
                                          {
                                                hlab.text="3";
                                                //hslide.value = 3;
                                                VBoxColor(3);
                                                if (txt3.text == "0")
                                                {
                                                      hlab.text="4";
                                                      //hslide.value = 4;
                                                      VBoxColor(4);
                                                      if (txt4.text == "0")
                                                      {
                                                            hlab.text="5";
                                                            //hslide.value = 5;
                                                            VBoxColor(5);
                                                            if (txt5.text == "0")
                                                            {
                                                                  hlab.text="6";
                                                                  //hslide.value = 6;
                                                                  VBoxColor(6);
                                                                  if (txt6.text == "0")
                                                                  {
                                                                        hlab.text="7";
                                                                        //hslide.value = 7;
                                                                        VBoxColor(7);
                                                                        if (txt7.text == "0")
                                                                        {
                                                                              hlab.text="8";
                                                                              //hslide.value = 8;
                                                                              VBoxColor(8);
                                                                        }
                                                                  }
                                                            }
                                                      }
                                                }
                                          }
                                          
                                          if (txt2.text !="0" || txt3.text !="0" || txt4.text !="0" || txt5.text !="0" || txt6.text !="0" || txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                              }
                              else if (hlab.text == "2" && chint == parseInt(txt2.text))
                              {
                                    
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          stopWatch.reset();
                                          playSound();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="3";
                                          //hslide.value = 3;
                                          VBoxColor(3);
                                          if (txt3.text == "0")
                                          {
                                                hlab.text="4";
                                                //hslide.value = 4;
                                                VBoxColor(4);
                                                if (txt4.text == "0")
                                                {
                                                      hlab.text="5";
                                                      //hslide.value = 5;
                                                      VBoxColor(5);
                                                      if (txt5.text == "0")
                                                      {
                                                            hlab.text="6";
                                                            //hslide.value = 6;
                                                            VBoxColor(6);
                                                            if (txt6.text == "0")
                                                            {
                                                                  hlab.text="7";
                                                                  //hslide.value = 7;
                                                                  VBoxColor(7);
                                                                  if (txt7.text == "0")
                                                                  {
                                                                        hlab.text="8";
                                                                        //hslide.value = 8;
                                                                        VBoxColor(8);
                                                                  }
                                                            }
                                                      }
                                                }
                                          }
                                          if (txt3.text !="0" || txt4.text !="0" || txt5.text !="0" || txt6.text !="0" || txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                                    
                              }
                              else if (hlab.text == "3" && chint == parseInt(txt3.text))
                              {
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          stopWatch.reset();
                                          playSound();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="4";
                                          //hslide.value = 4;
                                          VBoxColor(4);
                                          if (txt4.text == "0")
                                          {
                                                hlab.text="5";
                                                //hslide.value = 5;
                                                VBoxColor(5);
                                                if (txt5.text == "0")
                                                {
                                                      hlab.text="6";
                                                      //hslide.value = 6;
                                                      VBoxColor(6);
                                                      if (txt6.text == "0")
                                                      {
                                                            hlab.text="7";
                                                            //hslide.value = 7;
                                                            VBoxColor(7);
                                                            if (txt7.text == "0")
                                                            {
                                                                  hlab.text="8";
                                                                  //hslide.value = 8;
                                                                  VBoxColor(8);
                                                            }
                                                      }
                                                }
                                          }
                                          
                                          if (txt4.text !="0" || txt5.text !="0" || txt6.text !="0" || txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                              }
                              else if (hlab.text == "4" && chint == parseInt(txt4.text))
                              {
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          playSound();
                                          stopWatch.reset();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="5";
                                          //hslide.value = 5;
                                          VBoxColor(5);
                                          if (txt5.text == "0")
                                          {
                                                hlab.text="6";
                                                //hslide.value = 6;
                                                VBoxColor(6);
                                                if (txt6.text == "0")
                                                {
                                                      hlab.text="7";
                                                      //hslide.value = 7;
                                                      VBoxColor(7);
                                                      if (txt7.text == "0")
                                                      {
                                                            hlab.text="8";
                                                            //hslide.value = 8;
                                                            VBoxColor(8);
                                                      }
                                                }
                                          }
                                          if (txt5.text !="0" || txt6.text !="0" || txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                                    
                              }
                              else if (hlab.text == "5" && chint == parseInt(txt5.text))
                              {
                                    
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          playSound();
                                          stopWatch.reset();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="6";
                                          //hslide.value = 6;
                                          VBoxColor(6);
                                          if (txt6.text == "0")
                                          {
                                                hlab.text="7";
                                                //hslide.value = 7;
                                                VBoxColor(7);
                                                if (txt7.text == "0")
                                                {
                                                      hlab.text="8";
                                                      //hslide.value = 8;
                                                      VBoxColor(8);
                                                }
                                          }
                                          if (txt6.text !="0" || txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                                    
                              }
                              else if (hlab.text == "6" && chint == parseInt(txt6.text))
                              {
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          playSound();
                                          stopWatch.reset();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="7";
                                          //hslide.value = 7;
                                          VBoxColor(7);
                                          if (txt7.text == "0")
                                          {
                                                hlab.text="8";
                                                //hslide.value = 8;
                                                VBoxColor(8);
                                          }
                                          if (txt7.text !="0" || txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                                    
                              }
                              else if (hlab.text == "7" && chint == parseInt(txt7.text))
                              {
                                    
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          playSound();
                                          stopWatch.reset();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          hlab.text="8";
                                          //hslide.value = 8;
                                          VBoxColor(8);
                                          if (txt8.text !="0")
                                          {
                                                startWatch();      
                                          }
                                    
                              }
                              else if (hlab.text == "8" && chint == parseInt(txt8.text))
                              {
                                    
                                          swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                                          stopWatch.pause();
                                          isRunning = false;
                                          playSound();
                                          stopWatch.reset();
                                          swLabel.text = '00:00:00';
                                          //ssButton.label = 'Start';
                                          //hlab.text="8";
                                          //hslide.value = 1;
                                          VBoxColor(1);
                                          if (loop.text == "1")
                                          {
                                                hlab.text = "1";
                                                startWatch();
                                          }
                                          else
                                          {
                                                stopClick();
                                          }
                                    
                              }                              
                        }
                              
                  }
                  
                  private function startWatch():void {
                        swLabel.addEventListener(Event.ENTER_FRAME, updateTime);
                        
                        stopWatch.start();            
                        isRunning = true;
                  }
                  
                  private function VBoxColor(vbxInd:int):void
                  {
                        vb1.alpha = 1;
                        vb2.alpha = 1;
                        vb3.alpha = 1;
                        vb4.alpha = 1;
                        vb5.alpha = 1;
                        vb6.alpha = 1;
                        vb7.alpha = 1;
                        vb8.alpha = 1;
                        if (vbxInd == 1)
                        {
                              vb1.alpha=0.3;
                        }
                        else if (vbxInd == 2)
                        {
                              vb2.alpha=0.3;
                        }
                        else if (vbxInd == 3)
                        {
                              vb3.alpha=0.3;
                        }
                        else if (vbxInd == 4)
                        {
                              vb4.alpha=0.3;
                        }
                        else if (vbxInd == 5)
                        {
                              vb5.alpha=0.3;
                        }
                        else if (vbxInd == 6)
                        {
                              vb6.alpha=0.3;
                        }
                        else if (vbxInd == 7)
                        {
                              vb7.alpha=0.3;
                        }
                        else if (vbxInd == 8)
                        {
                              vb8.alpha=0.3;
                        }
                  }
                  private function playClick():void {
                        if (txt1.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt1.setFocus();
                              return;
                        }
                        if (txt2.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt2.setFocus();
                              return;
                        }
                        if (txt3.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt3.setFocus();
                              return;
                        }
                        if (txt4.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt4.setFocus();
                              return;
                        }
                        if (txt5.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt5.setFocus();
                              return;
                        }
                        if (txt6.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt6.setFocus();
                              return;
                        }
                        if (txt7.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt7.setFocus();
                              return;
                        }
                        if (txt8.text == "")
                        {
                              Alert.show("Blank Value is not Allowed !!!","AstralProjectNow.com");
                              txt8.setFocus();
                              return;
                        }
                        if (pause.text == "0")
                        {
                              hlab.text="1";
                              //hslide.value = 1;
                              VBoxColor(1);
                              if (txt1.text =="0")
                              {
                              hlab.text="2";
                              //hslide.value = 2;
                              //VBoxColor(2);
                              VBoxColor(2);
                              
                              if (txt2.text == "0")
                              {
                                    hlab.text="3";
                                    //hslide.value = 3;
                                    VBoxColor(3);
                                    if (txt3.text == "0")
                                    {
                                          hlab.text="4";
                                          //hslide.value = 4;
                                          VBoxColor(4);
                                          if (txt4.text == "0")
                                          {
                                                hlab.text="5";
                                                //hslide.value = 5;
                                                VBoxColor(5);
                                                if (txt5.text == "0")
                                                {
                                                      hlab.text="6";
                                                      //hslide.value = 6;
                                                      VBoxColor(6);
                                                      if (txt6.text == "0")
                                                      {
                                                            hlab.text="7";
                                                            //hslide.value = 7;
                                                            VBoxColor(7);
                                                            if (txt7.text == "0")
                                                            {
                                                                  hlab.text="8";
                                                                  //hslide.value = 8;
                                                                  VBoxColor(8);
                                                            }
                                                      }
                                                }
                                          }
                                    }
                              }
                        }
                        }
                        else
                        {
                              pause.text = "0";
                        }
                                                
                        if (isRunning == false) {
                              startWatch();
                              //ssButton.label = 'Stop';
                        }
                        else {
                              
                              //ssButton.label = 'Start';
                        }
                  }
                  private function loopClick():void {
                        /*if (loop.text == "0")
                        {
                              loop.text = "1";
                              loopimg.source = "loopoff.png";
                        }
                        else if (loop.text == "1")
                        {
                              loop.text = "0";
                              loopimg.source = "loopon.png";
                        }*/
                        if (chk1.selected)
                        {
                              loop.text = "1";
                        }
                        else
                        {
                              loop.text = "0";
                        }
                  }
                  private function muteClick(): void {
                        if (snd.text == "0")
                        {
                              snd.text = "1";
                              soundimg.source = "sound.png";
                        }
                        else if (snd.text == "1")
                        {
                              snd.text = "0";
                              soundimg.source = "mute.png";
                        }
                  }
                  private function stopClick():void {
                        swLabel.removeEventListener(Event.ENTER_FRAME, updateTime);
                        stopWatch.pause();
                        isRunning = false;
                        stopWatch.reset();
                        swLabel.text = '00:00:00';
                  }
                  
            ]]>
      </mx:Script>
      <mx:HBox width="180" height="28" verticalAlign="middle" x="590" y="168" alpha="1.0" themeColor="#35D5B9">
            <mx:LinkButton id="link1" label="www.xyz.com" click="navigateToURL(new URLRequest('http://www.xyz.com'), '_blank')" />
      </mx:HBox>
      <mx:HSlider x="671" y="110" width="100" minimum="1" maximum="10" id="vol"  snapInterval="1" tickInterval="1"/>
</mx:Application>

.css code

Button {
   cornerRadius: 0;
   fillAlphas: 0, 0, 0, 0;
   color: #FFFFFF;
   textRollOverColor: #FFFFFF;
   textSelectedColor: #000000;
   themeColor: #ff9900;
   fontFamily: Tahoma;
   fontSize: 11;
   fontWeight: bold;
}
ToolTip {
            backgroundAlpha: 1.0;
            backgroundColor: haloBlue;
            fontWeight: bold;
            color: white;
        }

HSlider {
                  thumbSkin: Embed(source="Assets/arrow.png");
            dataTipPlacement: right;
            dataTipOffset: 0;
                  trackColors: black;
                  trackMargin: 0;
}
            MySounda10{
                   url: Embed(source='a10.mp3');
             }
             MySounda20{
                   url: Embed(source='a20.mp3');
             }
             MySounda30{
                   url: Embed(source='a30.mp3');
             }
             MySoundb10{
                   url: Embed(source='b10.mp3');
             }
             MySoundb20{
                   url: Embed(source='b20.mp3');
             }
             MySoundb30{
                   url: Embed(source='b30.mp3');
             }
             MySoundc10{
                   url: Embed(source='c10.mp3');
             }
             MySoundc20{
                   url: Embed(source='c20.mp3');
             }
             MySoundc30{
                   url: Embed(source='c30.mp3');
             }
             MySoundd10{
                   url: Embed(source='d10.mp3');
             }
             MySoundd20{
                   url: Embed(source='d20.mp3');
             }
             MySoundd30{
                   url: Embed(source='d30.mp3');
             }
             MySounde10{
                   url: Embed(source='e10.mp3');
             }
             MySounde20{
                   url: Embed(source='e20.mp3');
             }
             MySoundde30{
                   url: Embed(source='e30.mp3');
             }
 LinkButton
 {
       over:#000000;
 }
 Alert
{
      
      backgroundAlpha: 0.3;
      backgroundColor: black;
      borderAlpha: 0.9;
      borderColor: black;
      dropShadowEnabled: true;
}


Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE