In order to use a pixel font in my textfields, I have created a font class in the Flash IDE. Then, I created a TextField instance with the font embedded with the anti aliasing set to bitmap. I export an SWC with all those things.
I created a class with a nice API to be able to deal with this stuff easily.
In FDT, I use class and this all works properly.
The issue here is that I now want to use one of these textfields as an input. I tried setting the textfield type to TextFieldType.INPUT, however the only thing that this does is allow me to select the text, I cannot type. I also created another asset with the type already set to input, does not work either.
I tried with just the asset, not with my class, and then I can type ok.
Is there something that prevents a textfield from being editable once it is part of a sprite? Here is the code of my class with the API:
package net.jansensan.as3fflikeui.text
{
// + ----------------------------------------
// [ IMPORTS ]
// + ----------------------------------------
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldType;
/**
* @author Mat Janson Blanchet
*/
public class BitmapTextfield extends Sprite
{
// + ----------------------------------------
// [ CONSTANTS ]
// + ----------------------------------------
[Embed(source="../assets/css/ui.css", mimeType="application/octet-stream")]
private const CSS :Class;
// + ----------------------------------------
// [ VARIABLES ]
// + ----------------------------------------
// display objects
private var _textfieldAsset :MovieClip;
private var _textfield :TextField;
private var _shadow :BitmapTextfieldAsset;
// private / protected
private var _styleSheet :StyleSheet;
// + ----------------------------------------
// [CONSTRUCTOR ]
// + ----------------------------------------
public function BitmapTextfield(type:String = TextFieldType.DYNAMIC)
{
switch(type)
{
case TextFieldType.DYNAMIC:
_textfieldAsset = new BitmapTextfieldAsset();
_textfield = _textfieldAsset.textfieldTXT;
_textfield.selectable = false;
break;
case TextFieldType.INPUT:
_textfieldAsset = new BitmapInputTextfieldAsset();
_textfield = _textfieldAsset.textfieldTXT;
_textfield.selectable = true;
break;
}
_textfield.htmlText = "";
_shadow = new BitmapTextfieldAsset();
_shadow.textfieldTXT.htmlText = "";
_shadow.x = 1;
_shadow.y = 1;
_styleSheet = new StyleSheet();
_styleSheet.parseCSS(new CSS());
setStyle(_styleSheet);
addChild(_shadow);
addChild(_textfieldAsset);
}
// + ----------------------------------------
// [ PUBLIC METHODS ]
// + ----------------------------------------
public function setWidth(newWidth:int):void
{
_textfield.width = newWidth;
_shadow.textfieldTXT.width = newWidth;
}
public function setHeight(newHeight:int):void
{
_textfield.height = newHeight;
_shadow.textfieldTXT.height = newHeight;
}
public function setStyle(newStyle:StyleSheet):void
{
_styleSheet = newStyle;
_textfield.styleSheet = _styleSheet;
}
public function setText(newText:String):void
{
_textfield.htmlText = newText;
_shadow.textfieldTXT.htmlText = newText;
}
public function getText():String
{
return _textfield.text;
}
public function getHTMLText():String
{
return _textfield.htmlText;
}
public function getTextNumLines():uint
{
return _textfield.numLines;
}
}
}
Any guidance would be useful, thanks in advance!
-mat.