A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Two font sizes in one dynamic text field

  1. #1
    Junior Member
    Join Date
    Jul 2006
    Location
    Boston, MA
    Posts
    11

    Two font sizes in one dynamic text field

    Hello,

    I'm trying to display the current time with am/pm, where the time is a large font and the am/pm is a smaller font. My as3 code for displaying the time with am/pm works and looks like this:

    //Adds the enter frame event to the dynamic text field.
    theTime.addEventListener(Event.ENTER_FRAME,showTim e);

    function showTime(event:Event):void {
    //Create a new instance of the date class.
    var myTime:Date = new Date();
    //This returns the minutes and the hour.
    var theMinutes=myTime.getMinutes();
    var theHours=myTime.getHours();
    var ampm:String;

    if((myTime.getHours() + myTime.getMinutes() / 60 + myTime.getSeconds() / 3600) < 12)
    {
    ampm = "AM";
    }
    else
    {
    ampm ="PM";
    }

    //This subtracts 12 from the hour when it greater than 13.
    if (theHours>=13) {
    theHours=theHours-12;
    }
    //Adds '0' if there is only one digit.
    if (String(theMinutes).length == 1) {
    theMinutes="0"+theMinutes;
    }
    //Displays the time in the dynamic text field.
    theTime.text =theHours+":"+theMinutes+" "+ampm;
    }


    I'm having trouble with varying the font sizes, though. Does anyone have any suggestions how to do this? I'm currently embedding the fonts with a dynamic text field called "theTime". I'd like to make the time Museo Sans 100, 280 pt and the AM/PM Museo Sans 100, 100 pt. I've tried using separate dynamic text fields, but that doesn't give me the flexibility that I need.

    Thanks in advance!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is a quick and easy way,
    PHP Code:
    //Adds the enter frame event to the dynamic text field.
    theTime.addEventListener(Event.ENTER_FRAME,showTime);

    function 
    showTime(event:Event):void
    {
        
    //Create a new instance of the date class.
        
    var myTime:Date = new Date();
        
    //This returns the minutes and the hour.
        
    var theMinutes myTime.getMinutes();
        var 
    theHours myTime.getHours();
        var 
    ampm:String;

        if ((
    myTime.getHours() + myTime.getMinutes() / 60 myTime.getSeconds() / 3600) < 12)
        {
            
    ampm "<font size='10'>AM";
        }
        else
        {
            
    ampm "<font size='10'>PM";
        }

        
    //This subtracts 12 from the hour when it greater than 13.
        
    if (theHours>=13)
        {
            
    theHours theHours 12;
        }
        
    //Adds '0' if there is only one digit.
        
    if (String(theMinutes).length == 1)
        {
            
    theMinutes "0" theMinutes;
        }
        
    //Displays the time in the dynamic text field.
        
    theTime.htmlText theHours ":" theMinutes " " ampm;


  3. #3
    Junior Member
    Join Date
    Jul 2006
    Location
    Boston, MA
    Posts
    11
    Awesome! Thanks! That worked and is super simple. I feel like a big dummy for not knowing how to do that. Heh.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center