I am normally a Flash IDE guy, but I’m starting out on Flex (actually, I’m using Flash Develop) and for the life of me I can’t get this to work. I’ve done searches and everyone says the same thing…
The good news is that I can compile the program with no errors now. The bad news is that the text just doesn’t show up! I know it’s being added to the display list because my mouse cursor turns into a text cursor when I mouse over the area it should be…
Anyway, here is my code. Any help is greatly appreciated:
package utils {
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
import flash.text.TextFormatAlign;
import flash.text.AntiAliasType;
import flash.text.TextFieldAutoSize;
import flash.filters.DropShadowFilter;
import flash.filters.BitmapFilterQuality;
public class CustomText extends TextField {
[Embed(source = "fonts/BAUHS93.TTF", fontFamily = "Bauhaus", fontWeight="bold", advancedAntiAliasing="true", mimeType = "application/x-font")] private var _bauhs:Class;
[Embed(source = "fonts/WINGDNG2.TTF", fontFamily = "WingDings2", fontWeight="bold", advancedAntiAliasing="true", mimeType = "application/x-font")] private var _wingDings2:Class;
[Embed(source = "fonts/MUSEOFORDELL-REGULAR.TTF", fontFamily = "Museo", fontWeight="bold", advancedAntiAliasing="true", mimeType = "application/x-font")] private var _museo:Class;
private var myFont:Font;
private var myFormat:TextFormat;
private var _textContent:String;
private var _thisColor:int;
public function CustomText(textContent:String, tSize:int, col:int, sans:Boolean, dropShad:Boolean = false, limit:int = 0, bolden:Boolean = false, underline:Boolean = false, alignment:String = "center", thisWidth:Number = 0, thisHeight:Number = 0, wingdings:Boolean = false, wordwrapping:Boolean = true) {
super();
if (thisWidth != 0) {
this.autoSize = "left";
this.width = thisWidth;
this.multiline = wordwrapping;
this.wordWrap = wordwrapping;
}
_textContent = textContent;
_thisColor = col;
myFormat = new TextFormat();
if (sans) myFont = new _bauhs();
else myFont = new _museo();
if (wingdings) myFont = new _wingDings2();
myFormat.size = tSize;
if (alignment == "center") myFormat.align = TextFormatAlign.CENTER;
else if (alignment == "left") myFormat.align = TextFormatAlign.LEFT;
else myFormat.align = TextFormatAlign.RIGHT;
myFormat.font = myFont.fontName;
myFormat.color = col;
myFormat.bold = bolden;
myFormat.underline = underline;
myFormat.rightMargin = 1;
this.border = false;
this.wordWrap = false;
this.defaultTextFormat = myFormat;
this.embedFonts = true;
this.antiAliasType = AntiAliasType.ADVANCED;
if (limit != 0) this.text = textContent.substring(0, limit);
else this.text = textContent;
if(thisWidth == 0) {
if (alignment == "center") this.autoSize = TextFieldAutoSize.CENTER;
else if (alignment == "left") this.autoSize = TextFieldAutoSize.LEFT;
else this.autoSize = TextFieldAutoSize.RIGHT;
} else {
this.wordWrap = wordwrapping;
this.multiline = wordwrapping;
this.width = thisWidth;
//this.height = thisHeight;
}
if (dropShad) addShadow();
this.embedFonts = true;
}
private function addShadow():void {
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.distance = 2;
dropShadow.angle = 45;
dropShadow.color = 0x00;
dropShadow.alpha = 1;
dropShadow.blurX = 4;
dropShadow.blurY = 4;
dropShadow.strength = 1;
dropShadow.quality = BitmapFilterQuality.HIGH;
dropShadow.inner = false;
dropShadow.knockout = false;
dropShadow.hideObject = false;
this.filters = new Array(dropShadow);
}
public function changeText(str:String):void {
this.text = str;
this.defaultTextFormat = myFormat;
this.embedFonts = true;
}
public function changeHTMLText(str:String):void {
this.htmlText = str;
this.defaultTextFormat = myFormat;
this.embedFonts = true;
}
public function highlightText():void {
myFormat.color = 0x0037342F;
this.defaultTextFormat = myFormat;
this.text = _textContent;
this.embedFonts = true;
}
public function unhighlightText():void {
myFormat.color = _thisColor;
this.defaultTextFormat = myFormat;
this.text = _textContent;
this.embedFonts = true;
}
}
}