Need help in adding countdown timers
EGBAR.Mary Aug 30, 2011 4:48 PMHi 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");
}


