A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] formatting and creating text strings to display as required.

  1. #1
    Member
    Join Date
    Aug 2014
    Posts
    51

    resolved [RESOLVED] formatting and creating text strings to display as required.

    Hi all,

    This may be a very simple issue though I have not found any simple solution to it so far. I have to do four multiplications like

    4 * 4 = 16, 6 * 3 = 18, 7 * 3 = 21 and 9 * 7 = 63.

    For each of these resuls I want each of the result with the tens digit as smaller in font and with a different color ( say Red) and the units digit to be larger and of another color (say Black) as shown in the attached image file. The result is to be displayed in a textfield.

    NumFormat.png


    Is there any way to do this, easily?

    Thanks all !

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

    This will work for the set pattern you have in your question, I'm sure you can alter it slightly if you need to change any of the formulas or add any other things.

    With a textfield called outputText on the stage use the code below

    PHP Code:
    var a:String String(Number(4));
    var 
    b:String String(Number(3));
    var 
    c:String String(Number(3));
    var 
    d:String String(Number(7));

    blackText = new TextFormat();
    blackText.color 0x000000;
    blackText.size 14;

    redText = new TextFormat();
    redText.color 0xFF0000;
    redText.size 20;

    outputText.text d;
    for (var 
    i:Number 0outputText.lengthi++)
    {
        if (
    == 1)
        {
            
    trace(i);
            
    outputText.setTextFormat(i,redText);
        }
        else
        {
            
    outputText.setTextFormat(i,blackText);
        }


  3. #3
    Member
    Join Date
    Aug 2014
    Posts
    51
    Hi fruitbeard,

    Thanks loads for the reply. I'll try this one out and revert soon.

    Thanks !

  4. #4
    Member
    Join Date
    Aug 2014
    Posts
    51
    Ok so that worked perfect fruitbeard. Thanks a lot. But I was just wondering if there is not a simpler way to format strings using regex kinda code in actionscript. Please enlighten.

Tags for this Thread

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