AS3:无法在带有嵌入像素字体的输入文本字段中键入内容
为了在我的文本字段中使用像素字体,我在 Flash IDE 中创建了一个字体类。然后,我创建了一个 TextField 实例,其中嵌入了抗锯齿设置为位图的字体。我导出包含所有这些内容的 SWC。
我创建了一个具有良好 API 的类,以便能够轻松处理这些内容。
在 FDT 中,我使用类,这一切都工作正常。
这里的问题是我现在想使用这些文本字段之一作为输入。我尝试将文本字段类型设置为 TextFieldType.INPUT,但是这样做的唯一作用是允许我选择文本,但我无法键入。我还创建了另一个资产,其类型已设置为输入,但也不起作用。
我尝试只使用资产,而不是我的班级,然后我可以输入正常。
一旦文本字段成为精灵的一部分,是否有什么东西会阻止它被编辑?这是我的 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;
}
}
}
任何指导都会有用,提前致谢!
-垫。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
带有样式表的文本字段不可编辑。换句话说,类型属性设置为
TextFieldType.INPUT
的文本字段将StyleSheet
应用于文本字段的默认文本,但内容将不再可编辑由用户。考虑使用TextFormat
类为输入文本字段指定样式。A text field with a style sheet is not editable. In other words, a text field with the type property set to
TextFieldType.INPUT
applies theStyleSheet
to the default text for the text field, but the content will no longer be editable by the user. Consider using theTextFormat
class to assign styles to input text fields.