ActionScript 2.0 Language Reference |
|
|
|
| ActionScript classes > TextSnapshot > getTextRunInfo (TextSnapshot.getTextRunInfo method) | |||
Returns an array of objects that contains information about a run of text. Each object corresponds to one character in the range of characters specified by the two method parameters.
Note: Using the getTextRunInfo() method for a large range of text can return a large object. Adobe recommends limiting the text range defined by the beginIndex and endIndex parameters.
Availability: ActionScript 1.0; Flash Player 7 - The SWF file must be published for Flash Player 6 or later, and must be played in Flash Player 7r19 or later.
beginIndex:Number - The index value of the first character in the range of characters.
endIndex:Number - The index value of the last character in the range of characters.
Array - An array of objects in which each object contains information about a specific character in the specified range. Each object contains the following properties:
indexInRun--A zero-based integer index of the character (relative to the entire string rather than the selected run of text).selected--A Boolean value that indicates whether the character is selected true; false otherwise.font--The name of the character's font.color--The combined alpha and color value of the character. The first two hexadecimal digits represent the alpha value, and the remaining digits represent the color value. (The example includes a method for converting decimal values to hexadecimal values.)height--The height of the character, in pixels.matrix_a, matrix_b, matrix_c, matrix_d, matrix_tx, and matrix_ty-- The values of a matrix that define the geometric transformation on the character. Normal, upright text always has a matrix of the form [1 0 0 1 x y], where x and y are the position of the character within the parent movie clip, regardless of the height of the text. The matrix is in the parent movie clip coordinate system, and does not include any transformations that may be on that movie clip itself (or its parent). corner0x, corner0y, corner1x, corner1y, corner2x, corner2y, corner3x, and corner3y--The corners of the bounding box of the character, based on the coordinate system of the parent movie clip. These values are only available if the font used by the character is embedded in the SWF file.The following example illustrates how to use this method. To use this code, on the Stage create a static text field that contains the text "AB". Rotate the text field by 45 degrees, and set the second character to be superscript with a color of 0xFFFFFF with a 50% alpha, as the following figure shows:

The following script lists the getTextRunInfo() properties of each character in the text field:
var myTS:TextSnapshot = this.getTextSnapshot();
var myArray:Array = myTS["getTextRunInfo"](0, myTS.getCount());
for (var i = 0; i < myTS.getCount(); i++) {
trace("indexInRun: " + myArray[i].indexInRun);
trace("selected: " + myArray[i].selected);
trace("font: " + myArray[i].font);
trace("color: " + decToHex(myArray[i].color));
trace("height: " + myArray[i].height);
trace("matrix_a: " + myArray[i].matrix_a);
trace("matrix_b: " + myArray[i].matrix_b);
trace("matrix_c: " + myArray[i].matrix_c);
trace("matrix_d: " + myArray[i].matrix_d);
trace("matrix_ty: " + myArray[i].matrix_tx);
trace("matrix_tx: " + myArray[i].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;
}
This creates the following output:
indexInRun: 0
selected: false
font: Times New Roman
color: FF000000
height: 28.6
matrix_a: 0.0316612236983293
matrix_b: 0.0385940558426864
matrix_c: -0.0385940558426864
matrix_d: 0.0316612236983293
matrix_ty: 22.75
matrix_tx: 40.35
indexInRun: 0
selected: false
font: Times New Roman
color: 80000000
height: 28.6
matrix_a: 0.0316612236983293
matrix_b: 0.0385940558426864
matrix_c: -0.0385940558426864
matrix_d: 0.0316612236983293
matrix_ty: 49
matrix_tx: 45.5
This example uses a decToHex() method to convert the decimal value of the color property to a hexadecimal value.
|
|
|
|