0 Replies Latest reply on Mar 16, 2009 2:09 PM by mtkidg

    Applying TextFormat to dynamic text

    mtkidg
      Here's the link:
      http://ingenuitydesigngroup.com/flashTests/startClock.html

      Okay:
      I have dynamic text fields for the clock in the file:
      hours_txt
      minutes_txt
      seconds_txt
      date_txt


      I've created a text format
      var formatDate:TextFormat = new TextFormat(); (red text etc)
      that I am applying to each of the text fields.

      Here's the question:
      When I apply the format within the function that updates the time (which runs once a second) -
      function ticktock(evt:TimerEvent) - the format is applied to the text.
      However, when I apply the format outside the function, it's ignored.
      seconds_txt.setTextFormat(formatDate);

      Can some one explain why?



      /startClock.html"> http://ingenuitydesigngroup.com/flashTests/startClock.html]http://ingenuitydesigngroup.com/flashTests/startClock.html]http://ingenuitydesigngroup.co m/flashTests<B[/L][/L]

      Here's the action script:

      var months:Array = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
      var monthDays:Array = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
      var current:Date = new Date();




      //Run the function every second to get the new time for the clock
      var timer_Start:Timer = new Timer(1000);
      timer_Start.addEventListener(TimerEvent.TIMER,ticktock);
      timer_Start.start();



      //function to update the clock every second
      function ticktock(evt:TimerEvent) {
      var current:Date = new Date();
      //This gets current time and changes the display of the AM/PM and hours
      var currHours:Number = current.getHours();
      if (currHours > 12) {
      currHours = currHours-12;
      timeDay_txt.text = "PM";
      }
      hours_txt.text= currHours.toString();
      hours_txt.setTextFormat(formatDate);
      //This gets current minutes and changes the display if less than 10
      var currMinutes:Number = current.getMinutes();
      if (currMinutes < 10) {
      minutes_txt.text= "0" + currMinutes.toString();
      } else {
      minutes_txt.text = currMinutes.toString();
      }
      minutes_txt.setTextFormat(formatDate);
      var currSeconds:Number = current.getSeconds();
      if (currSeconds < 10) {
      seconds_txt.text= "0" + currSeconds.toString();
      } else {
      seconds_txt.text = currSeconds.toString();
      }
      }

      //This gets current date and generates display
      var currMonthIndex:Number = current.getMonth();
      var currMonth = months[currMonthIndex];
      var currDate = current.getDate();
      var currYear = current.getFullYear();
      var date:String = currMonth + " " + currDate + ", " + currYear;
      date_txt.text = date;

      //styles
      var formatDate:TextFormat = new TextFormat();
      formatDate.align = TextFormatAlign.CENTER;
      formatDate.bold = true;
      formatDate.size ="20";
      formatDate.color = "0xff0000";

      date_txt.setTextFormat(formatDate);
      seconds_txt.setTextFormat(formatDate);

      //Sets up gauge length
      gaugeTotalMonth_mc.width = monthDays[currMonthIndex] * 6;
      gauge_Days.width = currDate * 6;

      var colorTransformGauge:ColorTransform = gauge_Days.transform.colorTransform;
      colorTransformGauge.color = 0x400000;
      gauge_Days.transform.colorTransform = colorTransformGauge; Text