-
[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 !
-
.
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 * 4));
var b:String = String(Number(6 * 3));
var c:String = String(Number(7 * 3));
var d:String = String(Number(9 * 7));
blackText = new TextFormat();
blackText.color = 0x000000;
blackText.size = 14;
redText = new TextFormat();
redText.color = 0xFF0000;
redText.size = 20;
outputText.text = a + b + c + d;
for (var i:Number = 0; i < outputText.length; i++)
{
if (i % 2 == 1)
{
trace(i);
outputText.setTextFormat(i,redText);
}
else
{
outputText.setTextFormat(i,blackText);
}
}
-
Hi fruitbeard,
Thanks loads for the reply. I'll try this one out and revert soon.
Thanks !
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|