一起使用 Flash AS2 embedFonts = true AND textField.onSetFocus() 时出现问题

发布于 2024-10-22 01:06:09 字数 1685 浏览 2 评论 0原文

我注意到 AS2 和在使用 createTextField() 添加到舞台的文本字段中使用字体时出现一些奇怪的行为。这是针对最初显示“年份”的文本字段 - 用户可以输入年份,单击“确定”,该年份被接受,然后文本字段恢复为“年份”。我希望它始终是无衬线字体,例如 Arial (当然这并不困难!)

这是我想要实现的目标 -

1)当用户单击文本字段时,单词“年份”被清除,并且闪烁的光标表示可以输入文字。 2)当用户单击“确定”(并提供年份是四位数字)时,文本字段会返回“年份”(Arial 格式)

我的代码 -

this.createTextField("uiYear", 99, 0, 0, 65, 20);
uiYear.type = "input";
uiYear.antiAliasType="advanced";
uiYear.restrict = "0-9";
//
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "Arial";
my_fmt.size = 12;
my_fmt.align = "left";
//
uiYear.embedFonts = true;
uiYear.setTextFormat(my_fmt);
uiYear.text = "Year";
//
uiYear.onSetFocus = function() {
  if(uiYear.text == "Year") {
      uiYear.text = "";
  }
}
//
button_ok.onRelease = function() {
  uiYear.text = "Year";
}

看起来不错吧?

我注意到的是 -

当我单击文本字段时,“年份”一词消失,但闪烁的光标不显示,并且我无法在文本字段中输入文本。如果我删除该行 -

uiYear.embedFonts = true;

...那么它就可以正常工作,“年份”一词消失,当我单击文本字段时,我可以在文本字段中输入数字。因此,嵌入字体似乎可以防止在触发 onSetFocus 函数后将焦点设置在 textField 上。然而,我现在输入的文本不是 Arial,当我单击“确定”按钮并且“年份”一词被替换时,它是衬线字体 - 例如 Times 或其他字体。我不想那样!

同样,如果我尝试嵌入库中的字体 - 例如,我的库中有一个新字体,我使用链接标识符year_font 将其导出到actionscript,并更改my_fmt.font=my_font,然后单击链接对话框中的Export for actionscript。然后,当我单击文本字段时,“年份”一词消失,但无法编辑文本字段。

如果我只是接受 onSetFocus 导致问题并继续保留看起来更好的嵌入字体,我会遇到更多问题 -

  1. 如果我单击文本字段,光标现在会出现在“年份”一词之后,正如我所期望的那样,因为我有删除了删除单词的 onSetFocus 函数。因此,如果我通过按退格键 4 次来删除“年份”,那么由于某种原因,光标会消失并且我无法输入文本。请注意,在本地测试时不会发生这种情况,但仅在浏览器中发布和运行时才会出现问题。
  2. 但是,如果我突出显示“年份”一词,然后开始输入,我就可以正常输入数字,如果我点击“确定”按钮,年份一词就会以正确的字体显示。奇怪的是,现在上面第 1 条中的行为不再发生 - 如果我按删除键删除年份一词,光标会保留下来,我可以再次输入。第一似乎只是第一次发生。

有什么想法吗?

谢谢

I am noticing some strange behaviour with AS2 and using fonts in a textField that is added to the stage using createTextField(). This is for a textField which originally says Year - and user can enter a year, click ok and the year is accepted then the textField reverts back to saying Year. I want this to always be a sans serif font, such as Arial (surely this cant be difficult!)

Here is what I want to achieve -

1) When user clicks on textField, the word "Year" is cleared and flashing cursor indicates that text can be entered.
2) When user clicks ok (and provided year is a four digit number) the textField goes back to saying "Year" (in Arial)

My code -

this.createTextField("uiYear", 99, 0, 0, 65, 20);
uiYear.type = "input";
uiYear.antiAliasType="advanced";
uiYear.restrict = "0-9";
//
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "Arial";
my_fmt.size = 12;
my_fmt.align = "left";
//
uiYear.embedFonts = true;
uiYear.setTextFormat(my_fmt);
uiYear.text = "Year";
//
uiYear.onSetFocus = function() {
  if(uiYear.text == "Year") {
      uiYear.text = "";
  }
}
//
button_ok.onRelease = function() {
  uiYear.text = "Year";
}

Looks ok right?

What i'm noticing is this -

When I click on the textField the word "Year" disappears but the flashing cursor doesnt show and I cant enter text into the textField. If I remove the line -

uiYear.embedFonts = true;

...then it works ok, the word "Year" disappears and I can type number into the textField when I click the textField. So embedding the fonts seems to prevent focus being set on the textField after the onSetFocus function is triggered. However the text i now enter is not Arial, when I click the ok button and the word "Year" is replaced it is in a serif font - like Times or something. I dont want that!

Similarly if I try to embed a font from my library - eg I have a new Font in my library that I export to actionscript with the linkage identifier year_font and change the my_fmt.font=my_font and click Export for actionscript in the linkage dialog. Then when I click the textField, the word Year disappears but the textField cannot be edited.

If I just accept that the onSetFocus is causing the problem and go with keeping the embedded fonts which looks much better I have more probs -

  1. If I click on the textField the cursor now appears after the word "Year" as I would expect because I have removed the onSetFocus function that deletes the word. So if I delete "Year" by pressing backspace 4 times then for some reason the cursor disappears and I cannot enter text. Note this does not happen when testing locally but is only a problem when published and running in browser.
  2. However if I highlight the word "Year" then start typing I am able to type in numbers ok and if I hit the button ok, the word year shows up in the right font. Strangely now the behaviour in number 1 above doesnt happen anymore - if I press delete to remove the word year the cursor stays and I can type again. Number 1 only seems to happen the first time.

Any ideas?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉南桥 2024-10-29 01:06:09

我无法回答您的完整请求,但我也经历过当您按退格键时 TextField 会自行终止,并且如果您标记文本/以不同的方式执行操作则不会自行终止。

这一定是一个错误,因为我们通过将目标玩家从 FP8 更改为 FP9 来解决它。这是一个横幅,我们自然会以最低的共同标准来制作它们,但这次我们放弃了这一点,转而选择真正有效的东西! :)

I can't answer on your complete request, but I have too experienced the TextField that kills itself when you hit backspace, and does NOT kill itself if you mark text / do stuff differently.

This has to be a bug, since we solved it by changed target player from FP8 to FP9. This was for a banner and naturally we produce them with the lowest common denominator, but this time we gave that up in favor of having something that actually works! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文