Flex 模块和自定义文本字段
这真是一件奇怪的事。我创建了自己的 CustomTextField 类,用于嵌入字体并设置 defaultTextFormat。这工作得很好,但由于某种原因,当我尝试在除父应用程序之外的任何模块中创建新的 CustomTextField 时,文本文本有时仅显示。
这是我的 CustomTextField 类:
package uk.package.text
{
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class CustomTextField extends TextField
{
[Embed(source='../assets/fonts/Arial.ttf',fontName='CustomFont',fontWeight='regular',
unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
mimeType='application/x-font-truetype'
)]
public static var MY_FONT:Class;
[Embed(source='../assets/fonts/Arial Bold.ttf',fontName='CustomFont',fontWeight='bold',
unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
mimeType='application/x-font-truetype'
)]
public static var MY_FONT_BOLD:Class;
public static const DEFAULT_FONT:String = "Arial";
public static const DEFAULT_TEXT_COLOUR:int = 0x000000;
public static const DEFAULT_TEXT_SIZE:int = 14;
private var _tf:TextFormat = new TextFormat(DEFAULT_FONT, DEFAULT_TEXT_SIZE, DEFAULT_TEXT_COLOUR);
public function CustomTextField():void
{
var CustomFont:Font = new MY_FONT();
_tf.font = CustomFont.fontName;
_tf.size = 16;
embedFonts = true;
antiAliasType = AntiAliasType.ADVANCED;
defaultTextFormat = _tf;
autoSize = TextFieldAutoSize.LEFT;
}
public override function set htmlText(value:String):void
{
super.htmlText = value;
setTextFormat(_tf);
}
public function get textFormat():TextFormat
{
return _tf;
}
}
}
很奇怪,有时它可以工作,有时却不能......也许模块发生了一些奇怪的事情?
This is a really strange one. I've created my own CustomTextField class which I am using to embed the font and set the defaultTextFormat. This is working absolutely fine, but for some reason when I try to create a new CustomTextField in any module but the parent application, text text is only showing sometimes.
Here is my CustomTextField class:
package uk.package.text
{
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class CustomTextField extends TextField
{
[Embed(source='../assets/fonts/Arial.ttf',fontName='CustomFont',fontWeight='regular',
unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
mimeType='application/x-font-truetype'
)]
public static var MY_FONT:Class;
[Embed(source='../assets/fonts/Arial Bold.ttf',fontName='CustomFont',fontWeight='bold',
unicodeRange='U+0020-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E,U+0080-U+00FF,U+0100-U+017F,U+0400-U+04FF,U+0370-U+03FF,U+1E00-U+1EFF',
mimeType='application/x-font-truetype'
)]
public static var MY_FONT_BOLD:Class;
public static const DEFAULT_FONT:String = "Arial";
public static const DEFAULT_TEXT_COLOUR:int = 0x000000;
public static const DEFAULT_TEXT_SIZE:int = 14;
private var _tf:TextFormat = new TextFormat(DEFAULT_FONT, DEFAULT_TEXT_SIZE, DEFAULT_TEXT_COLOUR);
public function CustomTextField():void
{
var CustomFont:Font = new MY_FONT();
_tf.font = CustomFont.fontName;
_tf.size = 16;
embedFonts = true;
antiAliasType = AntiAliasType.ADVANCED;
defaultTextFormat = _tf;
autoSize = TextFieldAutoSize.LEFT;
}
public override function set htmlText(value:String):void
{
super.htmlText = value;
setTextFormat(_tf);
}
public function get textFormat():TextFormat
{
return _tf;
}
}
}
It's weird how sometimes it works and sometimes it doesn't... perhaps there is something odd going on with the modules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这个问题我花了很长时间才弄清楚。我终于通过使用以下代码使其工作:
在模块加载器项中。
谢谢!
Ok, this one took me ages to figure out. I finally got it working by using the following code:
In the module loader item.
Thanks!
是的,这几乎肯定是模块问题。我以前见过类似的东西。我正在寻找答案,但我最初的想法是设置
moduleLoader.applicationDomain = ApplicationDomain.currentDomain
另一个问题是,如果您加载同一模块两次。如果是这样,您需要通过添加
file.swf?
或类似内容来使 url 唯一。yes it's almost definitely a module issue. I've seen something similar before. I'm searching out the answer but my initial thought is to set
moduleLoader.applicationDomain = ApplicationDomain.currentDomain
Another issue is if you're loading the same module twice. If so you need to make the url unique by adding
file.swf?<randomNumber>
or something similar.