Skip to main content
Participant
April 16, 2011
Question

Static Text Character Check

  • April 16, 2011
  • 2 replies
  • 798 views
I have 20 static text fields on the stage and need to build actionscript to look at each character in each field and determine the Font, Style (italic, bold), size and color of each character then report the results (text field, Character, index, font …).

The report needs to list each character along with it style, font color ect… .

Short Example (there are actual 20 static fields on the stage):

Static Field 1) The Brown Fox

The report I need to build
Field: Static Field 1
Character: T
Color: FF000000
Font: Aril
Size: 10
Style: Italic
Ect …..

Field: Static Field 1
Character: h
Color: FFFF0000
Font: Times New Roman
Size: 10
Style: Bold
Ect …..

Can anybody point me to the best way to handle this?

Thanks for any help!
This topic has been closed for replies.

2 replies

Ned Murphy
Legend
April 17, 2011

You can access a static textfield using actionscript, but you would have to target it using getChildAt as long as you either know where it lives or can determine that it is a StaticText object by going thru the display list testing for the class (see the help documents StaticText section for an example). But beyond that, the StaticText class does not have all the methods and properties that the TextField class has and does not have get/setTextFormat methods.

Inspiring
April 17, 2011

Your textfields will need to be dynamic, not static, to be accessible with actionscript. You should check out the "getTextFormat" method for TextField to see if does what you need http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html.

SwLyonAuthor
Participant
April 17, 2011

Thank you for your help.

I found the following code that works with static text that gets me almost there. I can't find out how to list the character style (bold or italic) though. If you have any thoughts please let me know.

var myTS:TextSnapshot=this.textSnapshot;
var myArray:Array=myTS["getTextRunInfo"](0,myTS.charCount);
var myChar:Array=myTS["getText"](0,myTS.charCount).split("");

for (var i = 0; i < myTS.charCount; i++) {

trace("Character: " + myChar);
trace("indexInRun: " + myArray.indexInRun);
trace("selected: " + myArray.selected);
trace("font: " + myArray.font);
trace("color: " + decToHex(myArray.color));
trace("height: " + myArray.height);
trace("matrix_a: " + myArray.matrix_a);
trace("matrix_b: " + myArray.matrix_b);
trace("matrix_c: " + myArray.matrix_c);
trace("matrix_d: " + myArray.matrix_d);
trace("matrix_ty: " + myArray.matrix_tx);
trace("matrix_tx: " + myArray.matrix_ty);
trace(" ");
}


function decToHex(dec:Number) {
var hexString:String="";
if (dec>15) {
  hexString=decToHex(Math.floor(dec/16));
}
var hexDigit = dec - 16 * (Math.floor(dec / 16));
if (hexDigit>9) {
  hexDigit=String.fromCharCode(hexDigit+55);
}
hexString=hexString+hexDigit;
return hexString;
}

kglad
Community Expert
Community Expert
April 17, 2011

you can't get font decoration from the textsnapshot class.  you're using most of the properties available so, if that doesn't give you enough info, you'll need to use dyanmic textfields.