Copy link to clipboard
Copied
As title says, the textbox which was created in a function disappears after being flipped (scaleX = -1). Is there any way to fix it? The textbox contains the value of health, and it belongs to an Enemy unit. When the enemy unit turns to face another direction, the textbox disappears.
Here's my function.
private function draw():void
{
healthTxt = new TextField();
healthTxt.defaultTextFormat = new TextFormat("Rockwell", 15, 0xFF0000, 1)
healthTxt.height = 20;
healthTxt.width = 20;
healthTxt.x = -10;
healthTxt.y = -28;
healthTxt.text = health + "";
addChild(healthTxt);
;
}
Everything was instantiated properly. Any help would be appreciated. Thanks!
If the unit contains the textfield, then the textfield will turn with the unit.
Copy link to clipboard
Copied
how is the textfield tied to the enyemy? Is it a child of enemy?
Copy link to clipboard
Copied
Yep.
Copy link to clipboard
Copied
If you manipulate the orientation of the textfield, such as flipping it or even rotating it, you need to embed the font. Otherwise the text will not display.
Copy link to clipboard
Copied
Hi Ned, thanks for the reply. I have already embedded the font (in this case, Rockwell bold) and it works when the unit gets hit by a bullet (i.e the hp decreases by 1). However, when I change the orientation the number still simply disappears. Any idea? Thanks!
Oh, if it helps, the code is in the enemy class.
Copy link to clipboard
Copied
I do not see anything that is embedding the font in the code you show.
Copy link to clipboard
Copied
Though I have not reviewed the accuracy of the information, here is a link that has a tutorial about embedding the font for dynamically created textfields:
Copy link to clipboard
Copied
Thanks for the quick reply Ned. I have embedded the font in Flash CS5. Does it work if I do it that way or must I do it the way which is specified under AS3?
EDIT: Sorry, I sort of fixed it by adding
healthTxt.embedFonts = true;.
However, when the unit turns now, the number flips together with it...
Copy link to clipboard
Copied
If the unit contains the textfield, then the textfield will turn with the unit.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now