Skip to main content
October 25, 2010
Question

Bug: Copying and pasting a htmlText ignores embed font???

  • October 25, 2010
  • 1 reply
  • 519 views

- Adobe Flash Pro CS4

- Reproducible in Flash player 9 and 10

There seems to be a bug when copying a string value from a "htmlText" textfield and then pasting it in a standard "text" textField, and then adding that text back into the htmlText textField, which in turn no longer displays any new text.

For example:

1. Type "hello" in input textField, and press [Send] button

2. "hello" appears in the display textField (as htmlText)

3. From the display textField, copy the word "hello" and paste it into the input textField.

4. Press [Send]

5. Now, if embedFont was enabled and assuming that there is a ArialReg font class defined via library, the display textField does not show the 2nd "hello" message, and it no longer display anything new. This is because it was not able to show the text that was embedded as another font. You can tell this by turning off embedFont. Repeat steps 1-4, note that the 2nd "hello" font differs to the 1st "hello" font - which caused the bug as per above.

Source code (requires ArialReg and fl.controls.Button defined via Library):

//Copy and paste into your main timeline.

import flash.events.Event;

import fl.controls.Button;


var enableEmbed:Boolean = false;


var format:TextFormat = new TextFormat();
format.font = new ArialReg().fontName;
format.bold = false
format.size = 12
format.color = 0x000000;
format.align = TextFormatAlign.LEFT
format.underline = false


var _chatBox:TextField = new TextField();
_chatBox.multiline = true;
_chatBox.selectable = true;
_chatBox.wordWrap = true;
_chatBox.multiline = true;
_chatBox.embedFonts = enableEmbed;
_chatBox.antiAliasType = "advanced";
_chatBox.tabEnabled = false;
_chatBox.mouseEnabled = true;
_chatBox.defaultTextFormat = format;
_chatBox.width = 260
_chatBox.height = 300
_chatBox.type = "dynamic";
_chatBox.x = 10;
_chatBox.y = 30;
_chatBox.mouseWheelEnabled = false
_chatBox.background = true;
_chatBox.border = true;


format = new TextFormat();
format.font = new ArialReg().fontName;
format.bold = false
format.size = 12
format.color = 0x000000;
format.align = TextFormatAlign.LEFT
format.underline = false


var _chatInput:TextField = new TextField();
_chatInput.multiline = true;
_chatInput.selectable = true;
_chatInput.wordWrap = true;
_chatInput.multiline = true;
_chatInput.embedFonts = enableEmbed;
_chatInput.antiAliasType = "advanced";
_chatInput.tabEnabled = false;
_chatInput.mouseEnabled = true;
_chatInput.defaultTextFormat = format;
_chatInput.width = 200;
_chatInput.height = 50;
_chatInput.type = "input";
_chatInput.x = 10;
_chatInput.y = _chatBox.y + _chatBox.height + 5;
_chatInput.mouseWheelEnabled = false;
_chatInput.background = true;
_chatInput.border = true;


var _chatSendBtn:Button = new Button();
_chatSendBtn.y = _chatInput.y;
_chatSendBtn.x = 215;
_chatSendBtn.width = 55
_chatSendBtn.height = _chatInput.height;
_chatSendBtn.addEventListener(MouseEvent.MOUSE_UP, onChatSendBtn);
_chatSendBtn.label = "Send";


this.addChild(_chatBox);
this.addChild(_chatInput);
this.addChild(_chatSendBtn);


function onChatSendBtn(mE:MouseEvent):void
{
    if (_chatInput.text != "")
    {
        _chatBox.htmlText += _chatInput.text;       
        _chatInput.text = "";
    }
}

This topic has been closed for replies.

1 reply

October 25, 2010

Note:

_chatBox.htmlText += _chatInput.text;       
_chatBox.setTextFormat(format);

will resolve the problem, but it introduces another bug - Using setTextFormat does not allow bold and regular font for embedFonts for htmlText, however defaultTextFormat does. As I need both bold and regular font for the textField, I can't use that workflow.

October 25, 2010

Okay.. apparently calling defaultTextFormat everytime prior to setting the htmlText e would resolve both issues:

i.e.

_chatBox.defaultTextFormat = format;

_chatBox.htmlText += _chatInput.text;