ࡱ> Root Entryp|YrRASHPeContents Page 1 Root Entryp|YrRASH36`Contents Page 1^ ! CPicPage CPicLayer CPicFrame?)q/* * Method: TextField.setEllipsisText() * Desc: Truncates text to fit in a text field, and adds * an ellipsis if necessary. * Params: theText Text to assign to the text field. */ TextField.prototype.setEllipsisText = function (theText) { // Retrieve the format for newly added text. var format = this.getNewTextFormat(); // Initialize the substring being assigned to the field. var theSubstring = theText; // Check how wide the text display area is. Subtract 8 // to account for the gutter between the text and the // text field's border. var textRegion = this._width - 8; // Assume the string is too wide to fit. var tooWide = true; // Check if our assumption is correct. for (var i = theSubstring.length - 1; tooWide == true && i > 0; i--) { // If the string is too wide to fit in the field... if (format.getTextExtent(theSubstring).width > textRegion) { // ...remove a character, add an ellipsis, then check again. theSubstring = theText.substr(0, i) + "..."; } else { // ...otherwise, the string will fit, so stop checking. tooWide = false; } } // Assign the corrected string to the text field. this.text = theSubstring; } this.createTextField("theField_txt", 1, 100, 100, 180, 60); theField_txt.border = true; theField_txt.setEllipsisText("If this text is too long it will be truncated.");  Layer 1OText("If this is too long it will be truncated.");  Layer 1Oield.prototype.setEllipsisText = function (theText) { var format = this.getTextFormat(); var tooWide = true; var theSubstring = theText; for (var i = theSubstring.length; tooWide == true && i > 0; i--) { trace(i + ": " + theSubstring); if (format.getTextEx) CDocumentPagePage 1Scene 1Ʃ<ש<*@hhhhh  CColorDef3PfP0PHP`Px333(3f<03CH3F`3Hxf0f30ff(0f5Hf<`f@x3330333xf3d03]H3Z`3Xx3333303f3PPH33Px`33Px33Pf30f33PHff3(PHf3<x`f3Cxf3Ffff`f03f0ffx0fkHfd`f`x3f033fPH3ffxPH3fdx`3f]x3fZff0f3fPHfff`ffP0xffPxffPH3HfHxH̙n`hx3H33x`3fx`3xx`3̙kx3dfHf3x`ff0xfx0xf̙dxf]`3`f``x`px3`33x3fx3x3xx3nf`f3xffxfxfxxfkx3xfxxxxx3x333f333xfxf3fffffxxH3 HfH(H2`8x`3 `f`̙`(`0xx3xfxx x(xPx3H33x`f3x`3(x`35x3<3`33xf3 x̙3x3(x323x33f3 333(xfH3fx`ff0xf(0xf<xfCf`3fxffx̙fxf(xf5fx3ffff ff((xH3x`f0x̙PPP`3xfx̙P̙(P<x3f̙(xx`3xfxPxPd`3xfx̙PPx3f(xx3fxx3f̙xx3f CPicPage CPicLayer CPicFrame?)/* * Method: TextField.setEllipsisText() * Desc: Truncates text to fit in a text field, and adds * an ellipsis if necessary. * Params: theText Text to assign to the text field. */ TextField.prototype.setEllipsisText = function (theText) { // Retrieve the format for newly added text. var format = this.getNewTextFormat(); // Initialize the substring being assigned to the field. var theSubstring = theText; // Check how wide the text display area is. Subtract 8 // to account for the gutter between the text and the // text field's border. var textRegion = this._width - 8; // Assume the string is too wide to fit. var tooWide = true; // Check if our assumption is correct. for (var i = theSubstring.length - 1; tooWide == true && i > 0; i--) { // If the string is too wide to fit in the field... if (format.getTextExtent(theSubstring).width > textRegion) { // ...remove a character, add an ellipsis, then check again. theSubstring = theText.substr(0, i) + "..."; } else { // ...otherwise, the string will fit, so stop checking. tooWide = false; } } // Assign the corrected string to the text field. this.text = theSubstring; } // Sample use of setEllipsisText(). this.createTextField("theField_txt", 1, 100, 100, 150, 60); theField_txt.border = true; theField_txt.setEllipsisText("If this text is too long it will be truncated.");  Layer 1O truncated.");  Layer 1Oield.prototype.setEllipsisText = function (theText) { var format = this.getTextFormat(); var tooWide = true; var theSubstring = theText; for (var i = theSubstring.length; tooWide == true && i > 0; i--) { trace(i + ": " + theSubstring); if (format.getTextEx) CDocumentPagePage 1Scene 1Ʃ<ש<*@hhhhh  CColorDef3PfP0PHP`Px333(3f<03CH3F`3Hxf0f30ff(0f5Hf<`f@x3330333xf3d03]H3Z`3Xx3333303f3PPH33Px`33Px33Pf30f33PHff3(PHf3<x`f3Cxf3Ffff`f03f0ffx0fkHfd`f`x3f033fPH3ffxPH3fdx`3f]x3fZff0f3fPHfff`ffP0xffPxffPH3HfHxH̙n`hx3H33x`3fx`3xx`3̙kx3dfHf3x`ff0xfx0xf̙dxf]`3`f``x`px3`33x3fx3x3xx3nf`f3xffxfxfxxfkx3xfxxxxx3x333f333xfxf3fffffxxH3 HfH(H2`8x`3 `f`̙`(`0xx3xfxx x(xPx3H33x`f3x`3(x`35x3<3`33xf3 x̙3x3(x323x33f3 333(xfH3fx`ff0xf(0xf<xfCf`3fxffx̙fxf(xf5fx3ffff ff((xH3x`f0x̙PPP`3xfx̙P̙(P<x3f̙(xx`3xfxPxPd`3xfx̙PPx3f(xx3fxx3f̙xx3ff`zf*]hf`zf*]h