Because I want to avoid repetive code, and I'm using a lot of text formats, I created a CustomTextFormat class in Flex Builder.
Another class, called CustomInputBox.as is using this object to create a format:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class CustomInputBox extends Sprite
{
public function CustomInputBox(xLoc:int, yLoc:int, width:uint, height:uint, password:Boolean = false, text:String = "", font:String = "Arial", fontColor:uint = 0x000000, fontSize:uint = 18, fontBold:Boolean = false)
{
var inputBox:TextField = new TextField();
inputBox.type = TextFieldType.INPUT;
inputBox.mouseEnabled = true;
inputBox.selectable = true;
inputBox.multiline = false;
inputBox.x = xLoc;
inputBox.y = yLoc;
inputBox.width = width;
inputBox.height = height;
inputBox.displayAsPassword = password;
var format:CustomTextFormat = new CustomTextFormat();
inputBox.defaultTextFormat = format;
inputBox.text = text;
addChild(inputBox);
}
}
}
The code of CustomTextFormat is as follows:
package
{
import flash.display.Sprite;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public class CustomTextFormat extends Sprite
{
public function CustomTextFormat(font:String = "Arial", fontColor:uint = 0x000000, fontSize:uint = 18, fontBold:Boolean = false, fontAlign:String = TextFormatAlign.LEFT)
{
var format:TextFormat = new TextFormat();
format.font = font;
format.color = fontColor;
format.size = fontSize;
format.bold = fontBold;
format.align = fontAlign;
}
}
}
Now, I'm getting error 1067 in the CustomInputBox.as file, it's a dutch error unfortunately (any way to set flex errors to english?):
1067: Impliciete afgedwongen omzetting van een waarde van het type CustomTextFormat in een niet-gerelateerd type flash.text:TextFormat. CustomInputBox.as
It's difficult to translate, but hopefuly the error number and the code are enough to identify my problem. I'm new to flash, and searched but couldn't find out what I am doing wrong.
Thanks in advance.