undefined
undefined

Reputation: 5328

Problem when using Flash AS2 embedFonts = true AND textField.onSetFocus() together

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

Upvotes: 0

Views: 1577

Answers (1)

Tackle
Tackle

Reputation: 323

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! :)

Upvotes: 1

Related Questions