6 Replies Latest reply: Sep 1, 2011 12:04 PM by EGBAR.Mary RSS

    Need help in adding countdown timers

    EGBAR.Mary Community Member

      Hi newbie here again. I have this random movie player with 6 buttons that play the individual movies. The random movies have a title and a countdown timer that is working. I am stuck. I cannot make the timer work on the individual buttons. Any help would be greatly appreciated.

       

      import flash.display.MovieClip;

      import flash.events.MouseEvent;

      import flash.text.TextField;

      import flash.text.Font;

      import flash.text.TextFormat;

      import flash.utils.Timer;

       

      //This is where the Stop Sound is

      function fl_ClickToStopAllSounds(event:MouseEvent):void

      {

      SoundMixer.stopAll();

      }

       

      //assign movies and titles

      var movieList:Array = [threePrinciples,newlyweds,manRap,boysToys,automotive,troopTradition];

      var movieTitle:Array = ["ThreePrinciples","Newlyweds","Man Rap","BoysToys","Automotive, Or..","Troop Traditions"];

      //trace (movieTitle[0]);

      var movieLength:Array = [30,60,58,28,30,30];

      //trace (movieLength[0]);

      //pick a random number

      var pickMovie = Math.floor(Math.random() * movieList.length);

      //assign seleceted movie clip and title

      var mc:MovieClip = new movieList[pickMovie];

      var mcTitle = movieTitle[pickMovie];

      var mcLength = movieLength[pickMovie];

      //individual timer

      var fl_SecondsToCountDown_3:Number = mcLength;

      var fl_CountDownTimerInstance_3:Timer = new Timer(1000,fl_SecondsToCountDown_3);

       

      //assign the buttons

      var buttonPrinciples:ButtonPrinciples = new ButtonPrinciples;

      var buttonNewlyweds:ButtonNewlyweds = new ButtonNewlyweds;

      var buttonManRap:ButtonManRap = new ButtonManRap;

      var buttonBoysToys:ButtonBoysToys = new ButtonBoysToys;

      var buttonAuto:ButtonAuto = new ButtonAuto;

      var buttonTroops:ButtonTroops = new ButtonTroops;

       

      //Play selected Movie in Main window

      addChild(mc);

      var lastAdded_mc:MovieClip = (mc);

      mc.x = 34;

      mc.y = 38;

      //individual title

      var display_txt:TextField;

             display_txt = new TextField();

      var lastAddedTitle:TextField = (display_txt);

        

      {

      display_txt.text = String("You are watching " + mcTitle + ".");

      display_txt.width = 400

      display_txt.x = 37;

      display_txt.y = 15;

      var format:TextFormat = new TextFormat;

      format.color = 0xFFFFFF;

      format.size = 15;

      format.font = "_Sans";

      format.align = "left";

      display_txt.setTextFormat(format);

      //Add it to the stage

      addChild(display_txt);

      }

      //Timer for Random Movies

      var myNumberTextBox:TextField = new TextField;

      myNumberTextBox = new TextField();

      var lastAddedTimer:TextField = (myNumberTextBox);

       

      fl_CountDownTimerInstance_3.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_3);

      fl_CountDownTimerInstance_3.start();

       

      function fl_CountDownTimerHandler_3(event:TimerEvent):void

      {

      myNumberTextBox.text = String(fl_SecondsToCountDown_3 +  " / " + mcLength + " seconds");

      fl_SecondsToCountDown_3--;

      myNumberTextBox.width = 150;

      myNumberTextBox.x = 335;

      myNumberTextBox.y = 15;

      var format:TextFormat = new TextFormat;

      format.color = 0xFFFFFF;

      format.size = 15;

      format.font = "_Sans";

      format.align = "right";

      myNumberTextBox.setTextFormat(format);

      //Add it to the stage

      addChild(myNumberTextBox);

      }

       

      //Add 6 Buttons below Main Window

      addChild(buttonPrinciples);

      buttonPrinciples.x = 34;

      buttonPrinciples.y = 312;

      buttonPrinciples.buttonMode = true;

       

      addChild(buttonNewlyweds);

      buttonNewlyweds.x = 111.60;

      buttonNewlyweds.y = 312;

      buttonNewlyweds.buttonMode = true;

       

       

      //If the first button is clicked ThreePrinciples is replaces Random Movie

      buttonPrinciples.addEventListener(MouseEvent.CLICK, button1Clicked);

       

      function button1Clicked(event:MouseEvent):void

      {

      if (mc)

      {

      if (mc.stage)

      {

      removeChild(mc);

      removeChild(display_txt);

      fl_CountDownTimerInstance_3.removeEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_3);

      removeChild(myNumberTextBox);

      }

      }

      if (lastAdded_mc)

      {

      if (lastAdded_mc.stage)

      {

      removeChild(lastAdded_mc);

      removeChild(lastAddedTitle);

      // removeChild(lastAddedTimer);

      }

      }

      SoundMixer.stopAll();

      //Display Individual Movies Titles, Countdown Timer, and MovieLength

      var button1Title_txt: TextField = (display_txt);

      button1Title_txt = new TextField();

       

      {

      button1Title_txt.text = String("You are watching "+ (movieTitle[0]) +".                          "+ fl_SecondsToCountDown_3 +  " / " + (movieLength[0]) + " seconds");

      button1Title_txt.width = 600

      button1Title_txt.x = 37;

      button1Title_txt.y = 15;

      var format:TextFormat = new TextFormat;

      format.color = 0xFFFFFF;

      format.size = 15;

      format.font = "_Sans";

      format.align = "left";

       

      button1Title_txt.setTextFormat(format);

      }

      var bruce:threePrinciples = new threePrinciples();

      //Add it to the stage

      addChild(bruce);

      addChild(button1Title_txt);

      //addChild(button1Timer);

      lastAdded_mc = bruce;

       

      lastAddedTitle = button1Title_txt;

      //lastAddedTimer = button1Timer;

      bruce.x = 34;

      bruce.y = 38;

      //trace("button clicked");

      }

        • 1. Re: Need help in adding countdown timers
          Ned Murphy CommunityMVP

          Where in your code are you trying to get a Timer to work with buttons?

          • 2. Re: Need help in adding countdown timers
            EGBAR.Mary Community Member

            After the button1clicked right after

             

            var button1Title_txt: TextField = (display_txt);
                button1Title_txt = new TextField();

            • 3. Re: Need help in adding countdown timers
              Ned Murphy CommunityMVP

              I still don't see any attempt to get a timer working where you said.

              • 4. Re: Need help in adding countdown timers
                EGBAR.Mary Community Member

                Oh sorry, I had deleted those lines. I will try to recreate again.

                • 5. Re: Need help in adding countdown timers
                  EGBAR.Mary Community Member

                  The timer adds itself to the window but just doesnt start. Will I need to create a separate timer for each movie or is there a way to call a timer out to any of the movieLengths in the array? 

                   

                   

                  //If the second button is clicked newlyweds replaces Random Movie

                  buttonNewlyweds.addEventListener(MouseEvent.CLICK, button2Clicked);

                   

                  function button2Clicked(event:MouseEvent):void

                  {

                  if (mc)

                  {

                  if (mc.stage)

                  {

                  removeChild(mc);

                  removeChild(display_txt);

                  fl_CountDownTimerInstance_3.removeEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_3);

                  removeChild(myNumberTextBox);

                  }

                  }

                   

                  if (lastAdded_mc)

                  {

                  if (lastAdded_mc.stage)

                  {

                  removeChild(lastAdded_mc);

                  removeChild(lastAddedTitle);

                  // fl_CountDownTimerInstance_3.removeEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_3);

                  // removeChild(lastAddedTimer);

                  }

                  }

                  SoundMixer.stopAll();

                   

                  var button2Title_txt: TextField = (display_txt);

                  button2Title_txt = new TextField();

                   

                   

                  fl_CountDownTimerInstance_3.addEventListener(TimerEvent.TIMER, fl_CountDownTimerHandler_3);

                  fl_CountDownTimerInstance_3.start();

                   

                   

                  {

                  {

                  button2Title_txt.text = String("You are watching "+ (movieTitle[1]) +".                                 "+ fl_SecondsToCountDown_3 +  " / " + (movieLength[1]) + " seconds");

                  button2Title_txt.width = 600

                  button2Title_txt.x = 37;

                  button2Title_txt.y = 15;

                  var format:TextFormat = new TextFormat;

                  format.color = 0xFFFFFF;

                  format.size = 15;

                  format.font = "_Sans";

                  format.align = "left";

                  button2Title_txt.setTextFormat(format);

                  }

                  var newly:newlyweds = new newlyweds();

                  addChild(newly);

                  addChild(button2Title_txt);

                  //addChild(button2Timer);

                   

                  lastAdded_mc = newly;

                  lastAddedTitle = button2Title_txt

                  //lastAddedTimer = button2Timer;

                  newly.x = 34;

                  newly.y = 38;

                  }

                  //trace("button clicked");

                  }

                   

                  • 6. Re: Need help in adding countdown timers
                    EGBAR.Mary Community Member

                    I am still trying to figure this out. Now each time I click "Button 1" the timer counts down by click, but has reset the timer to the proper movie length.

                     

                    {

                    button1Title_txt.text = String("You are watching "+ (movieTitle[0]) +".                          "+ fl_SecondsToCountDown_3 +  " / " + (movieLength[0]) + " seconds");

                    fl_CountDownTimerInstance_3.reset();

                    fl_CountDownTimerInstance_3.start();

                    fl_SecondsToCountDown_3--;

                    button1Title_txt.width = 600

                    button1Title_txt.x = 37;

                    button1Title_txt.y = 15;

                    var format:TextFormat = new TextFormat;

                    format.color = 0xFFFFFF;

                    format.size = 15;

                    format.font = "_Sans";

                    format.align = "left";

                    button1Title_txt.setTextFormat(format);

                    }

                     

                    Any ideas, or am I just wishing this could be possible?